@lightsparkdev/core 1.4.3 → 1.4.4
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 +7 -0
- package/README.md +0 -2
- package/dist/{chunk-36QHRQJC.js → chunk-ADHQHZNM.js} +11 -9
- package/dist/chunk-VY7NND44.js +713 -0
- package/dist/{index-gUXiTlhb.d.cts → index-CFQtMxrx.d.cts} +2 -1
- package/dist/{index-gUXiTlhb.d.ts → index-CFQtMxrx.d.ts} +2 -1
- package/dist/index.cjs +2585 -2573
- package/dist/index.d.cts +8 -171
- package/dist/index.d.ts +8 -171
- package/dist/index.js +25 -679
- package/dist/react-native/index.cjs +3111 -0
- package/dist/react-native/index.d.cts +175 -0
- package/dist/react-native/index.d.ts +175 -0
- package/dist/react-native/index.js +154 -0
- package/dist/utils/index.cjs +3 -0
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +3 -1
- package/package.json +15 -1
- package/src/Logger.ts +2 -1
- package/src/crypto/SigningKey.ts +4 -2
- package/src/index.ts +3 -11
- package/src/react-native/index.ts +2 -0
- package/src/requester/DefaultRequester.ts +46 -0
- package/src/requester/Requester.ts +11 -44
- package/src/requester/tests/DefaultRequester.test.ts +129 -0
- package/src/requester/tests/Requester.test.ts +23 -32
- package/src/shared.ts +10 -0
- package/src/utils/environment.ts +3 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Client } from 'graphql-ws';
|
|
2
|
+
import { Observable } from 'zen-observable-ts';
|
|
3
|
+
export { A as AppendUnitsOptions, ae as ById, ap as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, Y as CurrencyCodes, X as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ai as DeepPartial, D as DeprecatedCurrencyAmountObj, ad as ExpandRecursively, ah as ExtractByTypename, aj as JSONLiteral, al as JSONObject, ak as JSONType, ac as Maybe, am as NN, af as OmitTypename, ao as PartialBy, aq as RequiredKeys, S as SDKCurrencyAmountType, ar as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, R as bytesToHex, a2 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, W as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a1 as deleteLocalStorageItem, e as ensureArray, Q as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, V as getCurrentLocale, O as getErrorMsg, $ as getLocalStorageBoolean, _ as getLocalStorageConfigItem, T as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, M as isError, P as isErrorMsg, N as isErrorWithMessage, I as isNode, a5 as isNumber, aa as isObject, L as isReactNative, ab as isRecord, v as isSDKCurrencyAmount, J as isTest, ag as isType, a9 as isUint8Array, q as isUmaCurrencyAmount, a3 as linearInterpolate, Z as localeToCurrencyCode, F as localeToCurrencySymbol, a8 as lsidToUUID, x as mapCurrencyAmount, an as notNullUndefined, a6 as pollUntil, a4 as round, E as separateCurrencyStrParts, a0 as setLocalStorageBoolean, a7 as sleep, u as urlsafe_b64decode, at as zipcodeToState, as as zipcodeToStateCode } from '../index-CFQtMxrx.cjs';
|
|
4
|
+
|
|
5
|
+
type Headers = Record<string, string>;
|
|
6
|
+
type WsConnectionParams = Record<string, unknown>;
|
|
7
|
+
interface AuthProvider {
|
|
8
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
9
|
+
isAuthorized(): Promise<boolean>;
|
|
10
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Query<T> = {
|
|
14
|
+
/** The string representation of the query payload for graphQL. **/
|
|
15
|
+
queryPayload: string;
|
|
16
|
+
/** The variables that will be passed to the query. **/
|
|
17
|
+
variables?: {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The function that will be called to construct the object from the
|
|
22
|
+
* response. *
|
|
23
|
+
*/
|
|
24
|
+
constructObject: (rawData: any) => T | null;
|
|
25
|
+
/** The id of the node that will be used to sign the query. **/
|
|
26
|
+
signingNodeId?: string;
|
|
27
|
+
/** True if auth headers should be omitted for this query. **/
|
|
28
|
+
skipAuth?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare class LightsparkException extends Error {
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
extraInfo: Record<string, unknown> | undefined;
|
|
35
|
+
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare class LightsparkSigningException extends LightsparkException {
|
|
39
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type GeneratedKeyPair = {
|
|
43
|
+
publicKey: CryptoKey | string;
|
|
44
|
+
privateKey: CryptoKey | string;
|
|
45
|
+
keyAlias?: string;
|
|
46
|
+
};
|
|
47
|
+
type CryptoInterface = {
|
|
48
|
+
decryptSecretWithNodePassword: (cipher: string, encryptedSecret: string, nodePassword: string) => Promise<ArrayBuffer | null>;
|
|
49
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
50
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
51
|
+
getNonce: () => Promise<number>;
|
|
52
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
53
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
54
|
+
};
|
|
55
|
+
declare function decryptSecretWithNodePassword(cipher: string, encryptedSecret: string, nodePassword: string): Promise<ArrayBuffer | null>;
|
|
56
|
+
declare const DefaultCrypto: {
|
|
57
|
+
decryptSecretWithNodePassword: typeof decryptSecretWithNodePassword;
|
|
58
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
59
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
60
|
+
getNonce: () => Promise<number>;
|
|
61
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
62
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type OnlyKey = {
|
|
66
|
+
key: string;
|
|
67
|
+
alias?: never;
|
|
68
|
+
};
|
|
69
|
+
type OnlyAlias = {
|
|
70
|
+
key?: never;
|
|
71
|
+
alias: string;
|
|
72
|
+
};
|
|
73
|
+
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
74
|
+
declare const KeyOrAlias: {
|
|
75
|
+
key: (key: string) => OnlyKey;
|
|
76
|
+
alias: (alias: string) => OnlyAlias;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
declare enum SigningKeyType {
|
|
80
|
+
RSASigningKey = "RSASigningKey",
|
|
81
|
+
Secp256k1SigningKey = "Secp256k1SigningKey"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface Alias {
|
|
85
|
+
alias: string;
|
|
86
|
+
}
|
|
87
|
+
declare abstract class SigningKey {
|
|
88
|
+
readonly type: SigningKeyType;
|
|
89
|
+
constructor(type: SigningKeyType);
|
|
90
|
+
abstract sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
91
|
+
}
|
|
92
|
+
declare class RSASigningKey extends SigningKey {
|
|
93
|
+
private readonly privateKey;
|
|
94
|
+
private readonly cryptoImpl;
|
|
95
|
+
constructor(privateKey: CryptoKey | Alias, cryptoImpl: CryptoInterface);
|
|
96
|
+
sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
97
|
+
}
|
|
98
|
+
declare class Secp256k1SigningKey extends SigningKey {
|
|
99
|
+
private readonly privateKey;
|
|
100
|
+
constructor(privateKey: string);
|
|
101
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class NodeKeyCache {
|
|
105
|
+
private readonly cryptoImpl;
|
|
106
|
+
private idToKey;
|
|
107
|
+
constructor(cryptoImpl?: CryptoInterface);
|
|
108
|
+
loadKey(id: string, keyOrAlias: KeyOrAliasType, signingKeyType: SigningKeyType): Promise<SigningKey | null>;
|
|
109
|
+
getKey(id: string): SigningKey | undefined;
|
|
110
|
+
hasKey(id: string): boolean;
|
|
111
|
+
private stripPemTags;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare class Requester {
|
|
115
|
+
private readonly nodeKeyCache;
|
|
116
|
+
protected readonly schemaEndpoint: string;
|
|
117
|
+
private readonly sdkUserAgent;
|
|
118
|
+
private readonly authProvider;
|
|
119
|
+
protected readonly baseUrl: string;
|
|
120
|
+
private readonly cryptoImpl;
|
|
121
|
+
private readonly signingKey?;
|
|
122
|
+
private readonly fetchImpl;
|
|
123
|
+
protected wsClient: Promise<Client | null>;
|
|
124
|
+
protected resolveWsClient: ((value: Client | null) => void) | null;
|
|
125
|
+
constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
|
|
126
|
+
protected initWsClient(baseUrl: string, authProvider: AuthProvider): Promise<Client | null>;
|
|
127
|
+
executeQuery<T>(query: Query<T>): Promise<T | null>;
|
|
128
|
+
subscribe<T>(queryPayload: string, variables?: {
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}): Observable<{
|
|
131
|
+
data: T;
|
|
132
|
+
}>;
|
|
133
|
+
makeRawRequest(queryPayload: string, variables?: {
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
}, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any>;
|
|
136
|
+
private getSdkUserAgent;
|
|
137
|
+
protected stripProtocol(url: string): string;
|
|
138
|
+
private addSigningDataIfNeeded;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
declare class LightsparkAuthException extends LightsparkException {
|
|
142
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
declare class StubAuthProvider implements AuthProvider {
|
|
146
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
147
|
+
isAuthorized(): Promise<boolean>;
|
|
148
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
152
|
+
declare enum LoggingLevel {
|
|
153
|
+
Trace = 0,
|
|
154
|
+
Info = 1
|
|
155
|
+
}
|
|
156
|
+
declare class Logger {
|
|
157
|
+
context: string;
|
|
158
|
+
loggingEnabled: boolean;
|
|
159
|
+
loggingLevel: LoggingLevel;
|
|
160
|
+
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
161
|
+
setLevel(level: LoggingLevel): void;
|
|
162
|
+
setEnabled(enabled: boolean, level?: LoggingLevel): void;
|
|
163
|
+
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
164
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
165
|
+
info(message: string, ...rest: unknown[]): void;
|
|
166
|
+
}
|
|
167
|
+
declare const logger: Logger;
|
|
168
|
+
|
|
169
|
+
declare enum ServerEnvironment {
|
|
170
|
+
PRODUCTION = "production",
|
|
171
|
+
DEV = "dev"
|
|
172
|
+
}
|
|
173
|
+
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
174
|
+
|
|
175
|
+
export { type AuthProvider, type CryptoInterface, DefaultCrypto, type GeneratedKeyPair, KeyOrAlias, type KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, LoggingLevel, NodeKeyCache, type Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, logger };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { Client } from 'graphql-ws';
|
|
2
|
+
import { Observable } from 'zen-observable-ts';
|
|
3
|
+
export { A as AppendUnitsOptions, ae as ById, ap as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, Y as CurrencyCodes, X as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ai as DeepPartial, D as DeprecatedCurrencyAmountObj, ad as ExpandRecursively, ah as ExtractByTypename, aj as JSONLiteral, al as JSONObject, ak as JSONType, ac as Maybe, am as NN, af as OmitTypename, ao as PartialBy, aq as RequiredKeys, S as SDKCurrencyAmountType, ar as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, R as bytesToHex, a2 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, W as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a1 as deleteLocalStorageItem, e as ensureArray, Q as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, V as getCurrentLocale, O as getErrorMsg, $ as getLocalStorageBoolean, _ as getLocalStorageConfigItem, T as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, M as isError, P as isErrorMsg, N as isErrorWithMessage, I as isNode, a5 as isNumber, aa as isObject, L as isReactNative, ab as isRecord, v as isSDKCurrencyAmount, J as isTest, ag as isType, a9 as isUint8Array, q as isUmaCurrencyAmount, a3 as linearInterpolate, Z as localeToCurrencyCode, F as localeToCurrencySymbol, a8 as lsidToUUID, x as mapCurrencyAmount, an as notNullUndefined, a6 as pollUntil, a4 as round, E as separateCurrencyStrParts, a0 as setLocalStorageBoolean, a7 as sleep, u as urlsafe_b64decode, at as zipcodeToState, as as zipcodeToStateCode } from '../index-CFQtMxrx.js';
|
|
4
|
+
|
|
5
|
+
type Headers = Record<string, string>;
|
|
6
|
+
type WsConnectionParams = Record<string, unknown>;
|
|
7
|
+
interface AuthProvider {
|
|
8
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
9
|
+
isAuthorized(): Promise<boolean>;
|
|
10
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type Query<T> = {
|
|
14
|
+
/** The string representation of the query payload for graphQL. **/
|
|
15
|
+
queryPayload: string;
|
|
16
|
+
/** The variables that will be passed to the query. **/
|
|
17
|
+
variables?: {
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The function that will be called to construct the object from the
|
|
22
|
+
* response. *
|
|
23
|
+
*/
|
|
24
|
+
constructObject: (rawData: any) => T | null;
|
|
25
|
+
/** The id of the node that will be used to sign the query. **/
|
|
26
|
+
signingNodeId?: string;
|
|
27
|
+
/** True if auth headers should be omitted for this query. **/
|
|
28
|
+
skipAuth?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare class LightsparkException extends Error {
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
extraInfo: Record<string, unknown> | undefined;
|
|
35
|
+
constructor(code: string, message: string, extraInfo?: Record<string, unknown>);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare class LightsparkSigningException extends LightsparkException {
|
|
39
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type GeneratedKeyPair = {
|
|
43
|
+
publicKey: CryptoKey | string;
|
|
44
|
+
privateKey: CryptoKey | string;
|
|
45
|
+
keyAlias?: string;
|
|
46
|
+
};
|
|
47
|
+
type CryptoInterface = {
|
|
48
|
+
decryptSecretWithNodePassword: (cipher: string, encryptedSecret: string, nodePassword: string) => Promise<ArrayBuffer | null>;
|
|
49
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
50
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
51
|
+
getNonce: () => Promise<number>;
|
|
52
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
53
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
54
|
+
};
|
|
55
|
+
declare function decryptSecretWithNodePassword(cipher: string, encryptedSecret: string, nodePassword: string): Promise<ArrayBuffer | null>;
|
|
56
|
+
declare const DefaultCrypto: {
|
|
57
|
+
decryptSecretWithNodePassword: typeof decryptSecretWithNodePassword;
|
|
58
|
+
generateSigningKeyPair: () => Promise<GeneratedKeyPair>;
|
|
59
|
+
serializeSigningKey: (key: CryptoKey | string, format: "pkcs8" | "spki") => Promise<ArrayBuffer>;
|
|
60
|
+
getNonce: () => Promise<number>;
|
|
61
|
+
sign: (keyOrAlias: CryptoKey | string, data: Uint8Array) => Promise<ArrayBuffer>;
|
|
62
|
+
importPrivateSigningKey: (keyData: Uint8Array) => Promise<CryptoKey | string>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type OnlyKey = {
|
|
66
|
+
key: string;
|
|
67
|
+
alias?: never;
|
|
68
|
+
};
|
|
69
|
+
type OnlyAlias = {
|
|
70
|
+
key?: never;
|
|
71
|
+
alias: string;
|
|
72
|
+
};
|
|
73
|
+
type KeyOrAliasType = OnlyKey | OnlyAlias;
|
|
74
|
+
declare const KeyOrAlias: {
|
|
75
|
+
key: (key: string) => OnlyKey;
|
|
76
|
+
alias: (alias: string) => OnlyAlias;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
declare enum SigningKeyType {
|
|
80
|
+
RSASigningKey = "RSASigningKey",
|
|
81
|
+
Secp256k1SigningKey = "Secp256k1SigningKey"
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface Alias {
|
|
85
|
+
alias: string;
|
|
86
|
+
}
|
|
87
|
+
declare abstract class SigningKey {
|
|
88
|
+
readonly type: SigningKeyType;
|
|
89
|
+
constructor(type: SigningKeyType);
|
|
90
|
+
abstract sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
91
|
+
}
|
|
92
|
+
declare class RSASigningKey extends SigningKey {
|
|
93
|
+
private readonly privateKey;
|
|
94
|
+
private readonly cryptoImpl;
|
|
95
|
+
constructor(privateKey: CryptoKey | Alias, cryptoImpl: CryptoInterface);
|
|
96
|
+
sign(data: Uint8Array): Promise<ArrayBuffer>;
|
|
97
|
+
}
|
|
98
|
+
declare class Secp256k1SigningKey extends SigningKey {
|
|
99
|
+
private readonly privateKey;
|
|
100
|
+
constructor(privateKey: string);
|
|
101
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare class NodeKeyCache {
|
|
105
|
+
private readonly cryptoImpl;
|
|
106
|
+
private idToKey;
|
|
107
|
+
constructor(cryptoImpl?: CryptoInterface);
|
|
108
|
+
loadKey(id: string, keyOrAlias: KeyOrAliasType, signingKeyType: SigningKeyType): Promise<SigningKey | null>;
|
|
109
|
+
getKey(id: string): SigningKey | undefined;
|
|
110
|
+
hasKey(id: string): boolean;
|
|
111
|
+
private stripPemTags;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare class Requester {
|
|
115
|
+
private readonly nodeKeyCache;
|
|
116
|
+
protected readonly schemaEndpoint: string;
|
|
117
|
+
private readonly sdkUserAgent;
|
|
118
|
+
private readonly authProvider;
|
|
119
|
+
protected readonly baseUrl: string;
|
|
120
|
+
private readonly cryptoImpl;
|
|
121
|
+
private readonly signingKey?;
|
|
122
|
+
private readonly fetchImpl;
|
|
123
|
+
protected wsClient: Promise<Client | null>;
|
|
124
|
+
protected resolveWsClient: ((value: Client | null) => void) | null;
|
|
125
|
+
constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
|
|
126
|
+
protected initWsClient(baseUrl: string, authProvider: AuthProvider): Promise<Client | null>;
|
|
127
|
+
executeQuery<T>(query: Query<T>): Promise<T | null>;
|
|
128
|
+
subscribe<T>(queryPayload: string, variables?: {
|
|
129
|
+
[key: string]: unknown;
|
|
130
|
+
}): Observable<{
|
|
131
|
+
data: T;
|
|
132
|
+
}>;
|
|
133
|
+
makeRawRequest(queryPayload: string, variables?: {
|
|
134
|
+
[key: string]: unknown;
|
|
135
|
+
}, signingNodeId?: string | undefined, skipAuth?: boolean): Promise<any>;
|
|
136
|
+
private getSdkUserAgent;
|
|
137
|
+
protected stripProtocol(url: string): string;
|
|
138
|
+
private addSigningDataIfNeeded;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
declare class LightsparkAuthException extends LightsparkException {
|
|
142
|
+
constructor(message: string, extraInfo?: Record<string, unknown>);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
declare class StubAuthProvider implements AuthProvider {
|
|
146
|
+
addAuthHeaders(headers: Headers): Promise<Headers>;
|
|
147
|
+
isAuthorized(): Promise<boolean>;
|
|
148
|
+
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
152
|
+
declare enum LoggingLevel {
|
|
153
|
+
Trace = 0,
|
|
154
|
+
Info = 1
|
|
155
|
+
}
|
|
156
|
+
declare class Logger {
|
|
157
|
+
context: string;
|
|
158
|
+
loggingEnabled: boolean;
|
|
159
|
+
loggingLevel: LoggingLevel;
|
|
160
|
+
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
161
|
+
setLevel(level: LoggingLevel): void;
|
|
162
|
+
setEnabled(enabled: boolean, level?: LoggingLevel): void;
|
|
163
|
+
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
164
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
165
|
+
info(message: string, ...rest: unknown[]): void;
|
|
166
|
+
}
|
|
167
|
+
declare const logger: Logger;
|
|
168
|
+
|
|
169
|
+
declare enum ServerEnvironment {
|
|
170
|
+
PRODUCTION = "production",
|
|
171
|
+
DEV = "dev"
|
|
172
|
+
}
|
|
173
|
+
declare const apiDomainForEnvironment: (environment: ServerEnvironment) => string;
|
|
174
|
+
|
|
175
|
+
export { type AuthProvider, type CryptoInterface, DefaultCrypto, type GeneratedKeyPair, KeyOrAlias, type KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, LoggingLevel, NodeKeyCache, type Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, logger };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigKeys,
|
|
3
|
+
DefaultCrypto,
|
|
4
|
+
KeyOrAlias,
|
|
5
|
+
LightsparkAuthException_default,
|
|
6
|
+
LightsparkSigningException_default,
|
|
7
|
+
Logger,
|
|
8
|
+
LoggingLevel,
|
|
9
|
+
NodeKeyCache_default,
|
|
10
|
+
RSASigningKey,
|
|
11
|
+
Requester_default,
|
|
12
|
+
Secp256k1SigningKey,
|
|
13
|
+
ServerEnvironment_default,
|
|
14
|
+
SigningKey,
|
|
15
|
+
SigningKeyType,
|
|
16
|
+
StubAuthProvider,
|
|
17
|
+
apiDomainForEnvironment,
|
|
18
|
+
logger
|
|
19
|
+
} from "../chunk-VY7NND44.js";
|
|
20
|
+
import {
|
|
21
|
+
CurrencyUnit,
|
|
22
|
+
LightsparkException_default,
|
|
23
|
+
abbrCurrencyUnit,
|
|
24
|
+
b64decode,
|
|
25
|
+
b64encode,
|
|
26
|
+
bytesToHex,
|
|
27
|
+
clamp,
|
|
28
|
+
convertCurrencyAmount,
|
|
29
|
+
convertCurrencyAmountValue,
|
|
30
|
+
countryCodesToCurrencyCodes,
|
|
31
|
+
createSha256Hash,
|
|
32
|
+
defaultCurrencyCode,
|
|
33
|
+
deleteLocalStorageItem,
|
|
34
|
+
ensureArray,
|
|
35
|
+
errorToJSON,
|
|
36
|
+
formatCurrencyStr,
|
|
37
|
+
formatInviteAmount,
|
|
38
|
+
getCurrencyAmount,
|
|
39
|
+
getCurrentLocale,
|
|
40
|
+
getErrorMsg,
|
|
41
|
+
getLocalStorageBoolean,
|
|
42
|
+
getLocalStorageConfigItem,
|
|
43
|
+
hexToBytes,
|
|
44
|
+
isBare,
|
|
45
|
+
isBrowser,
|
|
46
|
+
isCurrencyAmountInputObj,
|
|
47
|
+
isCurrencyAmountObj,
|
|
48
|
+
isCurrencyAmountPreferenceObj,
|
|
49
|
+
isCurrencyMap,
|
|
50
|
+
isDeprecatedCurrencyAmountObj,
|
|
51
|
+
isError,
|
|
52
|
+
isErrorMsg,
|
|
53
|
+
isErrorWithMessage,
|
|
54
|
+
isNode,
|
|
55
|
+
isNumber,
|
|
56
|
+
isObject,
|
|
57
|
+
isReactNative,
|
|
58
|
+
isRecord,
|
|
59
|
+
isSDKCurrencyAmount,
|
|
60
|
+
isTest,
|
|
61
|
+
isType,
|
|
62
|
+
isUint8Array,
|
|
63
|
+
isUmaCurrencyAmount,
|
|
64
|
+
linearInterpolate,
|
|
65
|
+
localeToCurrencyCode,
|
|
66
|
+
localeToCurrencySymbol,
|
|
67
|
+
lsidToUUID,
|
|
68
|
+
mapCurrencyAmount,
|
|
69
|
+
notNullUndefined,
|
|
70
|
+
pollUntil,
|
|
71
|
+
round,
|
|
72
|
+
separateCurrencyStrParts,
|
|
73
|
+
setLocalStorageBoolean,
|
|
74
|
+
sleep,
|
|
75
|
+
urlsafe_b64decode,
|
|
76
|
+
zipcodeToState,
|
|
77
|
+
zipcodeToStateCode
|
|
78
|
+
} from "../chunk-ADHQHZNM.js";
|
|
79
|
+
export {
|
|
80
|
+
ConfigKeys,
|
|
81
|
+
CurrencyUnit,
|
|
82
|
+
DefaultCrypto,
|
|
83
|
+
KeyOrAlias,
|
|
84
|
+
LightsparkAuthException_default as LightsparkAuthException,
|
|
85
|
+
LightsparkException_default as LightsparkException,
|
|
86
|
+
LightsparkSigningException_default as LightsparkSigningException,
|
|
87
|
+
Logger,
|
|
88
|
+
LoggingLevel,
|
|
89
|
+
NodeKeyCache_default as NodeKeyCache,
|
|
90
|
+
RSASigningKey,
|
|
91
|
+
Requester_default as Requester,
|
|
92
|
+
Secp256k1SigningKey,
|
|
93
|
+
ServerEnvironment_default as ServerEnvironment,
|
|
94
|
+
SigningKey,
|
|
95
|
+
SigningKeyType,
|
|
96
|
+
StubAuthProvider,
|
|
97
|
+
abbrCurrencyUnit,
|
|
98
|
+
apiDomainForEnvironment,
|
|
99
|
+
b64decode,
|
|
100
|
+
b64encode,
|
|
101
|
+
bytesToHex,
|
|
102
|
+
clamp,
|
|
103
|
+
convertCurrencyAmount,
|
|
104
|
+
convertCurrencyAmountValue,
|
|
105
|
+
countryCodesToCurrencyCodes,
|
|
106
|
+
createSha256Hash,
|
|
107
|
+
defaultCurrencyCode,
|
|
108
|
+
deleteLocalStorageItem,
|
|
109
|
+
ensureArray,
|
|
110
|
+
errorToJSON,
|
|
111
|
+
formatCurrencyStr,
|
|
112
|
+
formatInviteAmount,
|
|
113
|
+
getCurrencyAmount,
|
|
114
|
+
getCurrentLocale,
|
|
115
|
+
getErrorMsg,
|
|
116
|
+
getLocalStorageBoolean,
|
|
117
|
+
getLocalStorageConfigItem,
|
|
118
|
+
hexToBytes,
|
|
119
|
+
isBare,
|
|
120
|
+
isBrowser,
|
|
121
|
+
isCurrencyAmountInputObj,
|
|
122
|
+
isCurrencyAmountObj,
|
|
123
|
+
isCurrencyAmountPreferenceObj,
|
|
124
|
+
isCurrencyMap,
|
|
125
|
+
isDeprecatedCurrencyAmountObj,
|
|
126
|
+
isError,
|
|
127
|
+
isErrorMsg,
|
|
128
|
+
isErrorWithMessage,
|
|
129
|
+
isNode,
|
|
130
|
+
isNumber,
|
|
131
|
+
isObject,
|
|
132
|
+
isReactNative,
|
|
133
|
+
isRecord,
|
|
134
|
+
isSDKCurrencyAmount,
|
|
135
|
+
isTest,
|
|
136
|
+
isType,
|
|
137
|
+
isUint8Array,
|
|
138
|
+
isUmaCurrencyAmount,
|
|
139
|
+
linearInterpolate,
|
|
140
|
+
localeToCurrencyCode,
|
|
141
|
+
localeToCurrencySymbol,
|
|
142
|
+
logger,
|
|
143
|
+
lsidToUUID,
|
|
144
|
+
mapCurrencyAmount,
|
|
145
|
+
notNullUndefined,
|
|
146
|
+
pollUntil,
|
|
147
|
+
round,
|
|
148
|
+
separateCurrencyStrParts,
|
|
149
|
+
setLocalStorageBoolean,
|
|
150
|
+
sleep,
|
|
151
|
+
urlsafe_b64decode,
|
|
152
|
+
zipcodeToState,
|
|
153
|
+
zipcodeToStateCode
|
|
154
|
+
};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -65,6 +65,7 @@ __export(utils_exports, {
|
|
|
65
65
|
isNode: () => isNode,
|
|
66
66
|
isNumber: () => isNumber,
|
|
67
67
|
isObject: () => isObject,
|
|
68
|
+
isReactNative: () => isReactNative,
|
|
68
69
|
isRecord: () => isRecord,
|
|
69
70
|
isSDKCurrencyAmount: () => isSDKCurrencyAmount,
|
|
70
71
|
isTest: () => isTest,
|
|
@@ -141,6 +142,7 @@ var isBrowser = typeof window !== "undefined" && typeof window.document !== "und
|
|
|
141
142
|
var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
142
143
|
var isTest = isNode && process.env.NODE_ENV === "test";
|
|
143
144
|
var isBare = typeof Bare !== "undefined";
|
|
145
|
+
var isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
|
|
144
146
|
|
|
145
147
|
// src/utils/hex.ts
|
|
146
148
|
var bytesToHex = (bytes) => {
|
|
@@ -2350,6 +2352,7 @@ function zipcodeToState(zipcode) {
|
|
|
2350
2352
|
isNode,
|
|
2351
2353
|
isNumber,
|
|
2352
2354
|
isObject,
|
|
2355
|
+
isReactNative,
|
|
2353
2356
|
isRecord,
|
|
2354
2357
|
isSDKCurrencyAmount,
|
|
2355
2358
|
isTest,
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AppendUnitsOptions,
|
|
1
|
+
export { A as AppendUnitsOptions, ae as ById, ap as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, Y as CurrencyCodes, X as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ai as DeepPartial, D as DeprecatedCurrencyAmountObj, ad as ExpandRecursively, ah as ExtractByTypename, aj as JSONLiteral, al as JSONObject, ak as JSONType, ac as Maybe, am as NN, af as OmitTypename, ao as PartialBy, aq as RequiredKeys, S as SDKCurrencyAmountType, ar as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, R as bytesToHex, a2 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, W as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a1 as deleteLocalStorageItem, e as ensureArray, Q as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, V as getCurrentLocale, O as getErrorMsg, $ as getLocalStorageBoolean, _ as getLocalStorageConfigItem, T as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, M as isError, P as isErrorMsg, N as isErrorWithMessage, I as isNode, a5 as isNumber, aa as isObject, L as isReactNative, ab as isRecord, v as isSDKCurrencyAmount, J as isTest, ag as isType, a9 as isUint8Array, q as isUmaCurrencyAmount, a3 as linearInterpolate, Z as localeToCurrencyCode, F as localeToCurrencySymbol, a8 as lsidToUUID, x as mapCurrencyAmount, an as notNullUndefined, a6 as pollUntil, a4 as round, E as separateCurrencyStrParts, a0 as setLocalStorageBoolean, a7 as sleep, u as urlsafe_b64decode, at as zipcodeToState, as as zipcodeToStateCode } from '../index-CFQtMxrx.cjs';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as AppendUnitsOptions,
|
|
1
|
+
export { A as AppendUnitsOptions, ae as ById, ap as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, Y as CurrencyCodes, X as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ai as DeepPartial, D as DeprecatedCurrencyAmountObj, ad as ExpandRecursively, ah as ExtractByTypename, aj as JSONLiteral, al as JSONObject, ak as JSONType, ac as Maybe, am as NN, af as OmitTypename, ao as PartialBy, aq as RequiredKeys, S as SDKCurrencyAmountType, ar as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, R as bytesToHex, a2 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, W as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a1 as deleteLocalStorageItem, e as ensureArray, Q as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, V as getCurrentLocale, O as getErrorMsg, $ as getLocalStorageBoolean, _ as getLocalStorageConfigItem, T as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, M as isError, P as isErrorMsg, N as isErrorWithMessage, I as isNode, a5 as isNumber, aa as isObject, L as isReactNative, ab as isRecord, v as isSDKCurrencyAmount, J as isTest, ag as isType, a9 as isUint8Array, q as isUmaCurrencyAmount, a3 as linearInterpolate, Z as localeToCurrencyCode, F as localeToCurrencySymbol, a8 as lsidToUUID, x as mapCurrencyAmount, an as notNullUndefined, a6 as pollUntil, a4 as round, E as separateCurrencyStrParts, a0 as setLocalStorageBoolean, a7 as sleep, u as urlsafe_b64decode, at as zipcodeToState, as as zipcodeToStateCode } from '../index-CFQtMxrx.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
isNode,
|
|
35
35
|
isNumber,
|
|
36
36
|
isObject,
|
|
37
|
+
isReactNative,
|
|
37
38
|
isRecord,
|
|
38
39
|
isSDKCurrencyAmount,
|
|
39
40
|
isTest,
|
|
@@ -54,7 +55,7 @@ import {
|
|
|
54
55
|
urlsafe_b64decode,
|
|
55
56
|
zipcodeToState,
|
|
56
57
|
zipcodeToStateCode
|
|
57
|
-
} from "../chunk-
|
|
58
|
+
} from "../chunk-ADHQHZNM.js";
|
|
58
59
|
export {
|
|
59
60
|
CurrencyUnit,
|
|
60
61
|
abbrCurrencyUnit,
|
|
@@ -91,6 +92,7 @@ export {
|
|
|
91
92
|
isNode,
|
|
92
93
|
isNumber,
|
|
93
94
|
isObject,
|
|
95
|
+
isReactNative,
|
|
94
96
|
isRecord,
|
|
95
97
|
isSDKCurrencyAmount,
|
|
96
98
|
isTest,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
+
"react-native": "./dist/react-native/index.js",
|
|
27
28
|
"import": "./dist/index.js",
|
|
28
29
|
"require": "./dist/index.cjs"
|
|
29
30
|
},
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
"src/*",
|
|
40
41
|
"dist/*",
|
|
41
42
|
"dist/utils/*",
|
|
43
|
+
"dist/react-native/*",
|
|
42
44
|
"CHANGELOG.md"
|
|
43
45
|
],
|
|
44
46
|
"scripts": {
|
|
@@ -51,6 +53,7 @@
|
|
|
51
53
|
"lint:fix": "eslint --fix .",
|
|
52
54
|
"lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
|
|
53
55
|
"lint": "eslint .",
|
|
56
|
+
"circular-deps": "madge --circular --extensions ts,tsx src",
|
|
54
57
|
"package:checks": "yarn publint && yarn attw --pack .",
|
|
55
58
|
"postversion": "yarn build",
|
|
56
59
|
"test-cmd": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail",
|
|
@@ -81,6 +84,7 @@
|
|
|
81
84
|
"eslint-watch": "^8.0.0",
|
|
82
85
|
"jest": "^29.6.2",
|
|
83
86
|
"lodash-es": "^4.17.21",
|
|
87
|
+
"madge": "^6.1.0",
|
|
84
88
|
"prettier": "3.0.3",
|
|
85
89
|
"prettier-plugin-organize-imports": "^3.2.4",
|
|
86
90
|
"publint": "^0.3.9",
|
|
@@ -89,6 +93,16 @@
|
|
|
89
93
|
"tsup": "^8.2.4",
|
|
90
94
|
"typescript": "^5.6.2"
|
|
91
95
|
},
|
|
96
|
+
"madge": {
|
|
97
|
+
"detectiveOptions": {
|
|
98
|
+
"ts": {
|
|
99
|
+
"skipTypeImports": true
|
|
100
|
+
},
|
|
101
|
+
"tsx": {
|
|
102
|
+
"skipTypeImports": true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
92
106
|
"engines": {
|
|
93
107
|
"node": ">=18"
|
|
94
108
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ConfigKeys
|
|
1
|
+
import { ConfigKeys } from "./constants/index.js";
|
|
2
2
|
import { isBrowser, isTest } from "./utils/environment.js";
|
|
3
|
+
import { getLocalStorageConfigItem } from "./utils/localStorage.js";
|
|
3
4
|
|
|
4
5
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
5
6
|
|
package/src/crypto/SigningKey.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import secp256k1 from "secp256k1";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createSha256Hash } from "../utils/createHash.js";
|
|
3
|
+
import { hexToBytes } from "../utils/hex.js";
|
|
4
|
+
import type { CryptoInterface } from "./crypto.js";
|
|
5
|
+
import { SigningKeyType } from "./types.js";
|
|
4
6
|
|
|
5
7
|
interface Alias {
|
|
6
8
|
alias: string;
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
// Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export * from "./
|
|
6
|
-
export { default as LightsparkException } from "./LightsparkException.js";
|
|
7
|
-
export { Logger, LoggingLevel, logger } from "./Logger.js";
|
|
8
|
-
export * from "./requester/index.js";
|
|
9
|
-
export {
|
|
10
|
-
default as ServerEnvironment,
|
|
11
|
-
apiDomainForEnvironment,
|
|
12
|
-
} from "./ServerEnvironment.js";
|
|
13
|
-
export * from "./utils/index.js";
|
|
3
|
+
export { DefaultRequester as Requester } from "./requester/DefaultRequester.js";
|
|
4
|
+
export { default as Query } from "./requester/Query.js";
|
|
5
|
+
export * from "./shared.js";
|