@lightsparkdev/core 1.0.13 → 1.0.15
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 +12 -0
- package/dist/{chunk-ADJSE2YZ.js → chunk-ZLX5HJ4C.js} +3 -0
- package/dist/{index-d0c72658.d.ts → index-2708d41b.d.ts} +2 -1
- package/dist/index.cjs +17 -8
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +15 -9
- 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 +1 -1
- package/package.json +1 -1
- package/src/Logger.ts +17 -1
- package/src/requester/Requester.ts +4 -8
- package/src/utils/errors.ts +3 -0
- package/src/utils/types.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -729,6 +729,9 @@ var isErrorMsg = (e, msg) => {
|
|
|
729
729
|
return false;
|
|
730
730
|
};
|
|
731
731
|
function errorToJSON(err) {
|
|
732
|
+
if (!err) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
732
735
|
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
733
736
|
return err.toJSON();
|
|
734
737
|
}
|
|
@@ -161,6 +161,7 @@ type JSONType = JSONLiteral | JSONType[] | {
|
|
|
161
161
|
type JSONObject = {
|
|
162
162
|
[key: string]: JSONType;
|
|
163
163
|
};
|
|
164
|
+
type NN<T> = NonNullable<T>;
|
|
164
165
|
|
|
165
166
|
declare const isError: (e: unknown) => e is Error;
|
|
166
167
|
type ErrorWithMessage = {
|
|
@@ -268,4 +269,4 @@ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getV
|
|
|
268
269
|
|
|
269
270
|
declare function sleep(ms: number): Promise<unknown>;
|
|
270
271
|
|
|
271
|
-
export { JSONType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, pollUntil as S, sleep as T, Maybe as U, ExpandRecursively as V, ById as W, OmitTypename as X, isType as Y, DeepPartial as Z, JSONLiteral as _, b64encode as a, JSONObject as a0, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyAmountType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
|
|
272
|
+
export { JSONType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, pollUntil as S, sleep as T, Maybe as U, ExpandRecursively as V, ById as W, OmitTypename as X, isType as Y, DeepPartial as Z, JSONLiteral as _, b64encode as a, JSONObject as a0, NN as a1, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyAmountType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
|
package/dist/index.cjs
CHANGED
|
@@ -112,10 +112,14 @@ var isTest = isNode && process.env.NODE_ENV === "test";
|
|
|
112
112
|
var Logger = class {
|
|
113
113
|
context;
|
|
114
114
|
loggingEnabled = false;
|
|
115
|
+
loggingLevel = 1 /* Info */;
|
|
115
116
|
constructor(loggerContext, getLoggingEnabled) {
|
|
116
117
|
this.context = loggerContext;
|
|
117
118
|
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
118
119
|
}
|
|
120
|
+
setLevel(level) {
|
|
121
|
+
this.loggingLevel = level;
|
|
122
|
+
}
|
|
119
123
|
async updateLoggingEnabled(getLoggingEnabled) {
|
|
120
124
|
if (getLoggingEnabled) {
|
|
121
125
|
this.loggingEnabled = await getLoggingEnabled();
|
|
@@ -133,8 +137,13 @@ var Logger = class {
|
|
|
133
137
|
console.log(`[${this.context}] Logging enabled`);
|
|
134
138
|
}
|
|
135
139
|
}
|
|
140
|
+
trace(message, ...rest) {
|
|
141
|
+
if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
|
|
142
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
136
145
|
info(message, ...rest) {
|
|
137
|
-
if (this.loggingEnabled) {
|
|
146
|
+
if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
|
|
138
147
|
console.log(`[${this.context}] ${message}`, ...rest);
|
|
139
148
|
}
|
|
140
149
|
}
|
|
@@ -1123,6 +1132,9 @@ var isErrorMsg = (e, msg) => {
|
|
|
1123
1132
|
return false;
|
|
1124
1133
|
};
|
|
1125
1134
|
function errorToJSON(err) {
|
|
1135
|
+
if (!err) {
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1126
1138
|
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
1127
1139
|
return err.toJSON();
|
|
1128
1140
|
}
|
|
@@ -1384,8 +1396,6 @@ var import_graphql_ws = require("graphql-ws");
|
|
|
1384
1396
|
var import_ws = __toESM(require("ws"), 1);
|
|
1385
1397
|
var import_zen_observable_ts = require("zen-observable-ts");
|
|
1386
1398
|
var DEFAULT_BASE_URL = "api.lightspark.com";
|
|
1387
|
-
var LIGHTSPARK_BETA_HEADER_KEY = "X-Lightspark-Beta";
|
|
1388
|
-
var LIGHTSPARK_BETA_HEADER_VALUE = "z2h0BBYxTA83cjW7fi8QwWtBPCzkQKiemcuhKY08LOo";
|
|
1389
1399
|
import_dayjs.default.extend(import_utc.default);
|
|
1390
1400
|
var Requester = class {
|
|
1391
1401
|
constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto) {
|
|
@@ -1421,14 +1431,14 @@ var Requester = class {
|
|
|
1421
1431
|
return query.constructObject(data);
|
|
1422
1432
|
}
|
|
1423
1433
|
subscribe(queryPayload, variables = {}) {
|
|
1424
|
-
logger.
|
|
1434
|
+
logger.trace(`Requester.subscribe variables`, variables);
|
|
1425
1435
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
1426
1436
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
1427
1437
|
if (!operationMatch || operationMatch.length < 3) {
|
|
1428
1438
|
throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
|
|
1429
1439
|
}
|
|
1430
1440
|
const operationType = operationMatch[1];
|
|
1431
|
-
logger.
|
|
1441
|
+
logger.trace(`Requester.subscribe operationType`, operationType);
|
|
1432
1442
|
if (operationType == "mutation") {
|
|
1433
1443
|
throw new LightsparkException_default(
|
|
1434
1444
|
"InvalidQuery",
|
|
@@ -1447,7 +1457,7 @@ var Requester = class {
|
|
|
1447
1457
|
operationName: operation
|
|
1448
1458
|
};
|
|
1449
1459
|
return new import_zen_observable_ts.Observable((observer) => {
|
|
1450
|
-
logger.
|
|
1460
|
+
logger.trace(`Requester.subscribe observer`, observer);
|
|
1451
1461
|
return this.wsClient.subscribe(bodyData, {
|
|
1452
1462
|
next: (data) => observer.next(data),
|
|
1453
1463
|
error: (err) => observer.error(err),
|
|
@@ -1483,7 +1493,6 @@ var Requester = class {
|
|
|
1483
1493
|
const sdkUserAgent = this.getSdkUserAgent();
|
|
1484
1494
|
const baseHeaders = {
|
|
1485
1495
|
"Content-Type": "application/json",
|
|
1486
|
-
[LIGHTSPARK_BETA_HEADER_KEY]: LIGHTSPARK_BETA_HEADER_VALUE,
|
|
1487
1496
|
"X-Lightspark-SDK": sdkUserAgent,
|
|
1488
1497
|
"User-Agent": browserUserAgent || sdkUserAgent
|
|
1489
1498
|
};
|
|
@@ -1498,7 +1507,7 @@ var Requester = class {
|
|
|
1498
1507
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
1499
1508
|
}
|
|
1500
1509
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
1501
|
-
logger.
|
|
1510
|
+
logger.trace(`Requester.makeRawRequest`, {
|
|
1502
1511
|
url,
|
|
1503
1512
|
operationName: operation,
|
|
1504
1513
|
variables
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-
|
|
1
|
+
export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, a1 as NN, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-2708d41b.js';
|
|
2
2
|
import { Observable } from 'zen-observable-ts';
|
|
3
3
|
|
|
4
4
|
declare class LightsparkException extends Error {
|
|
@@ -9,11 +9,18 @@ declare class LightsparkException extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare enum LoggingLevel {
|
|
13
|
+
Trace = 0,
|
|
14
|
+
Info = 1
|
|
15
|
+
}
|
|
12
16
|
declare class Logger {
|
|
13
17
|
context: string;
|
|
14
18
|
loggingEnabled: boolean;
|
|
19
|
+
loggingLevel: LoggingLevel;
|
|
15
20
|
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
21
|
+
setLevel(level: LoggingLevel): void;
|
|
16
22
|
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
23
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
17
24
|
info(message: string, ...rest: unknown[]): void;
|
|
18
25
|
}
|
|
19
26
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-
|
|
1
|
+
export { W as ById, C as ConfigKeys, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, a1 as NN, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from './index-2708d41b.js';
|
|
2
2
|
import { Observable } from 'zen-observable-ts';
|
|
3
3
|
|
|
4
4
|
declare class LightsparkException extends Error {
|
|
@@ -9,11 +9,18 @@ declare class LightsparkException extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare enum LoggingLevel {
|
|
13
|
+
Trace = 0,
|
|
14
|
+
Info = 1
|
|
15
|
+
}
|
|
12
16
|
declare class Logger {
|
|
13
17
|
context: string;
|
|
14
18
|
loggingEnabled: boolean;
|
|
19
|
+
loggingLevel: LoggingLevel;
|
|
15
20
|
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
21
|
+
setLevel(level: LoggingLevel): void;
|
|
16
22
|
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
23
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
17
24
|
info(message: string, ...rest: unknown[]): void;
|
|
18
25
|
}
|
|
19
26
|
|
package/dist/index.js
CHANGED
|
@@ -40,16 +40,20 @@ import {
|
|
|
40
40
|
setLocalStorageBoolean,
|
|
41
41
|
sleep,
|
|
42
42
|
urlsafe_b64decode
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-ZLX5HJ4C.js";
|
|
44
44
|
|
|
45
45
|
// src/Logger.ts
|
|
46
46
|
var Logger = class {
|
|
47
47
|
context;
|
|
48
48
|
loggingEnabled = false;
|
|
49
|
+
loggingLevel = 1 /* Info */;
|
|
49
50
|
constructor(loggerContext, getLoggingEnabled) {
|
|
50
51
|
this.context = loggerContext;
|
|
51
52
|
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
52
53
|
}
|
|
54
|
+
setLevel(level) {
|
|
55
|
+
this.loggingLevel = level;
|
|
56
|
+
}
|
|
53
57
|
async updateLoggingEnabled(getLoggingEnabled) {
|
|
54
58
|
if (getLoggingEnabled) {
|
|
55
59
|
this.loggingEnabled = await getLoggingEnabled();
|
|
@@ -67,8 +71,13 @@ var Logger = class {
|
|
|
67
71
|
console.log(`[${this.context}] Logging enabled`);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
trace(message, ...rest) {
|
|
75
|
+
if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
|
|
76
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
70
79
|
info(message, ...rest) {
|
|
71
|
-
if (this.loggingEnabled) {
|
|
80
|
+
if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
|
|
72
81
|
console.log(`[${this.context}] ${message}`, ...rest);
|
|
73
82
|
}
|
|
74
83
|
}
|
|
@@ -446,8 +455,6 @@ import { createClient } from "graphql-ws";
|
|
|
446
455
|
import NodeWebSocket from "ws";
|
|
447
456
|
import { Observable } from "zen-observable-ts";
|
|
448
457
|
var DEFAULT_BASE_URL = "api.lightspark.com";
|
|
449
|
-
var LIGHTSPARK_BETA_HEADER_KEY = "X-Lightspark-Beta";
|
|
450
|
-
var LIGHTSPARK_BETA_HEADER_VALUE = "z2h0BBYxTA83cjW7fi8QwWtBPCzkQKiemcuhKY08LOo";
|
|
451
458
|
dayjs.extend(utc);
|
|
452
459
|
var Requester = class {
|
|
453
460
|
constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto) {
|
|
@@ -483,14 +490,14 @@ var Requester = class {
|
|
|
483
490
|
return query.constructObject(data);
|
|
484
491
|
}
|
|
485
492
|
subscribe(queryPayload, variables = {}) {
|
|
486
|
-
logger.
|
|
493
|
+
logger.trace(`Requester.subscribe variables`, variables);
|
|
487
494
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
488
495
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
489
496
|
if (!operationMatch || operationMatch.length < 3) {
|
|
490
497
|
throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
|
|
491
498
|
}
|
|
492
499
|
const operationType = operationMatch[1];
|
|
493
|
-
logger.
|
|
500
|
+
logger.trace(`Requester.subscribe operationType`, operationType);
|
|
494
501
|
if (operationType == "mutation") {
|
|
495
502
|
throw new LightsparkException_default(
|
|
496
503
|
"InvalidQuery",
|
|
@@ -509,7 +516,7 @@ var Requester = class {
|
|
|
509
516
|
operationName: operation
|
|
510
517
|
};
|
|
511
518
|
return new Observable((observer) => {
|
|
512
|
-
logger.
|
|
519
|
+
logger.trace(`Requester.subscribe observer`, observer);
|
|
513
520
|
return this.wsClient.subscribe(bodyData, {
|
|
514
521
|
next: (data) => observer.next(data),
|
|
515
522
|
error: (err) => observer.error(err),
|
|
@@ -545,7 +552,6 @@ var Requester = class {
|
|
|
545
552
|
const sdkUserAgent = this.getSdkUserAgent();
|
|
546
553
|
const baseHeaders = {
|
|
547
554
|
"Content-Type": "application/json",
|
|
548
|
-
[LIGHTSPARK_BETA_HEADER_KEY]: LIGHTSPARK_BETA_HEADER_VALUE,
|
|
549
555
|
"X-Lightspark-SDK": sdkUserAgent,
|
|
550
556
|
"User-Agent": browserUserAgent || sdkUserAgent
|
|
551
557
|
};
|
|
@@ -560,7 +566,7 @@ var Requester = class {
|
|
|
560
566
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
561
567
|
}
|
|
562
568
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
563
|
-
logger.
|
|
569
|
+
logger.trace(`Requester.makeRawRequest`, {
|
|
564
570
|
url,
|
|
565
571
|
operationName: operation,
|
|
566
572
|
variables
|
package/dist/utils/index.cjs
CHANGED
|
@@ -804,6 +804,9 @@ var isErrorMsg = (e, msg) => {
|
|
|
804
804
|
return false;
|
|
805
805
|
};
|
|
806
806
|
function errorToJSON(err) {
|
|
807
|
+
if (!err) {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
807
810
|
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
808
811
|
return err.toJSON();
|
|
809
812
|
}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-
|
|
1
|
+
export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, a1 as NN, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-2708d41b.js';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-
|
|
1
|
+
export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, a1 as NN, X as OmitTypename, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-2708d41b.js';
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
package/src/Logger.ts
CHANGED
|
@@ -3,15 +3,25 @@ import { isBrowser, isTest } from "./utils/environment.js";
|
|
|
3
3
|
|
|
4
4
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
5
5
|
|
|
6
|
+
export enum LoggingLevel {
|
|
7
|
+
Trace,
|
|
8
|
+
Info,
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export class Logger {
|
|
7
12
|
context: string;
|
|
8
13
|
loggingEnabled = false;
|
|
14
|
+
loggingLevel: LoggingLevel = LoggingLevel.Info;
|
|
9
15
|
|
|
10
16
|
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled) {
|
|
11
17
|
this.context = loggerContext;
|
|
12
18
|
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
13
19
|
}
|
|
14
20
|
|
|
21
|
+
public setLevel(level: LoggingLevel) {
|
|
22
|
+
this.loggingLevel = level;
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
async updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled) {
|
|
16
26
|
if (getLoggingEnabled) {
|
|
17
27
|
this.loggingEnabled = await getLoggingEnabled();
|
|
@@ -32,8 +42,14 @@ export class Logger {
|
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
|
|
45
|
+
trace(message: string, ...rest: unknown[]) {
|
|
46
|
+
if (this.loggingEnabled && this.loggingLevel === LoggingLevel.Trace) {
|
|
47
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
info(message: string, ...rest: unknown[]) {
|
|
36
|
-
if (this.loggingEnabled) {
|
|
52
|
+
if (this.loggingEnabled && this.loggingLevel <= LoggingLevel.Info) {
|
|
37
53
|
console.log(`[${this.context}] ${message}`, ...rest);
|
|
38
54
|
}
|
|
39
55
|
}
|
|
@@ -21,9 +21,6 @@ import { b64encode } from "../utils/base64.js";
|
|
|
21
21
|
import { isNode } from "../utils/environment.js";
|
|
22
22
|
|
|
23
23
|
const DEFAULT_BASE_URL = "api.lightspark.com";
|
|
24
|
-
export const LIGHTSPARK_BETA_HEADER_KEY = "X-Lightspark-Beta";
|
|
25
|
-
export const LIGHTSPARK_BETA_HEADER_VALUE =
|
|
26
|
-
"z2h0BBYxTA83cjW7fi8QwWtBPCzkQKiemcuhKY08LOo";
|
|
27
24
|
dayjs.extend(utc);
|
|
28
25
|
|
|
29
26
|
type BodyData = {
|
|
@@ -77,14 +74,14 @@ class Requester {
|
|
|
77
74
|
queryPayload: string,
|
|
78
75
|
variables: { [key: string]: unknown } = {},
|
|
79
76
|
) {
|
|
80
|
-
logger.
|
|
77
|
+
logger.trace(`Requester.subscribe variables`, variables);
|
|
81
78
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
82
79
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
83
80
|
if (!operationMatch || operationMatch.length < 3) {
|
|
84
81
|
throw new LightsparkException("InvalidQuery", "Invalid query payload");
|
|
85
82
|
}
|
|
86
83
|
const operationType = operationMatch[1];
|
|
87
|
-
logger.
|
|
84
|
+
logger.trace(`Requester.subscribe operationType`, operationType);
|
|
88
85
|
if (operationType == "mutation") {
|
|
89
86
|
throw new LightsparkException(
|
|
90
87
|
"InvalidQuery",
|
|
@@ -105,7 +102,7 @@ class Requester {
|
|
|
105
102
|
};
|
|
106
103
|
|
|
107
104
|
return new Observable<{ data: T }>((observer) => {
|
|
108
|
-
logger.
|
|
105
|
+
logger.trace(`Requester.subscribe observer`, observer);
|
|
109
106
|
return this.wsClient.subscribe(bodyData, {
|
|
110
107
|
next: (data) => observer.next(data as { data: T }),
|
|
111
108
|
error: (err) => observer.error(err),
|
|
@@ -150,7 +147,6 @@ class Requester {
|
|
|
150
147
|
const sdkUserAgent = this.getSdkUserAgent();
|
|
151
148
|
const baseHeaders = {
|
|
152
149
|
"Content-Type": "application/json",
|
|
153
|
-
[LIGHTSPARK_BETA_HEADER_KEY]: LIGHTSPARK_BETA_HEADER_VALUE,
|
|
154
150
|
"X-Lightspark-SDK": sdkUserAgent,
|
|
155
151
|
"User-Agent": browserUserAgent || sdkUserAgent,
|
|
156
152
|
};
|
|
@@ -173,7 +169,7 @@ class Requester {
|
|
|
173
169
|
|
|
174
170
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
175
171
|
|
|
176
|
-
logger.
|
|
172
|
+
logger.trace(`Requester.makeRawRequest`, {
|
|
177
173
|
url,
|
|
178
174
|
operationName: operation,
|
|
179
175
|
variables,
|
package/src/utils/errors.ts
CHANGED
package/src/utils/types.ts
CHANGED
|
@@ -31,3 +31,5 @@ export type DeepPartial<T> = T extends object
|
|
|
31
31
|
export type JSONLiteral = string | number | boolean | null;
|
|
32
32
|
export type JSONType = JSONLiteral | JSONType[] | { [key: string]: JSONType };
|
|
33
33
|
export type JSONObject = { [key: string]: JSONType };
|
|
34
|
+
|
|
35
|
+
export type NN<T> = NonNullable<T>;
|