@featbit/js-client-sdk 3.0.13 → 3.0.14
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/LICENSE +21 -21
- package/README.md +301 -301
- package/dist/esm/IFbClientCore.d.ts +1 -1
- package/dist/esm/IFbClientCore.d.ts.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/{featbit-js-client-sdk-3.0.13.js → featbit-js-client-sdk-3.0.14.js} +2 -2
- package/dist/umd/featbit-js-client-sdk-3.0.14.js.map +1 -0
- package/dist/umd/featbit-js-client-sdk.js +1 -1
- package/dist/umd/featbit-js-client-sdk.js.map +1 -1
- package/package.json +46 -46
- package/src/Configuration.ts +232 -232
- package/src/Context.ts +61 -61
- package/src/FbClientBuilder.ts +167 -167
- package/src/FbClientCore.ts +405 -405
- package/src/IContextProperty.ts +3 -3
- package/src/IDataKind.ts +11 -11
- package/src/IFbClient.ts +29 -29
- package/src/IFbClientCore.ts +290 -290
- package/src/IVersionedData.ts +18 -18
- package/src/bootstrap/IBootstrapProvider.ts +4 -4
- package/src/bootstrap/JsonBootstrapProvider.ts +34 -34
- package/src/bootstrap/NullBootstrapProvider.ts +20 -20
- package/src/bootstrap/index.ts +2 -2
- package/src/constants.ts +1 -1
- package/src/data-sources/DataSourceUpdates.ts +116 -116
- package/src/data-sources/createStreamListeners.ts +67 -67
- package/src/data-sources/index.ts +1 -1
- package/src/data-sync/DataSyncMode.ts +3 -3
- package/src/data-sync/IDataSynchronizer.ts +15 -15
- package/src/data-sync/IRequestor.ts +10 -10
- package/src/data-sync/NullDataSynchronizer.ts +14 -14
- package/src/data-sync/PollingDataSynchronizer.ts +125 -125
- package/src/data-sync/Requestor.ts +61 -61
- package/src/data-sync/WebSocketDataSynchronizer.ts +77 -77
- package/src/data-sync/index.ts +8 -8
- package/src/data-sync/types.ts +19 -19
- package/src/data-sync/utils.ts +31 -31
- package/src/errors.ts +47 -47
- package/src/evaluation/EvalResult.ts +35 -35
- package/src/evaluation/Evaluator.ts +26 -26
- package/src/evaluation/IEvalDetail.ts +23 -23
- package/src/evaluation/ReasonKinds.ts +9 -9
- package/src/evaluation/data/IFlag.ts +29 -29
- package/src/evaluation/index.ts +4 -4
- package/src/events/DefaultEventProcessor.ts +83 -83
- package/src/events/DefaultEventQueue.ts +49 -49
- package/src/events/DefaultEventSender.ts +73 -73
- package/src/events/DefaultEventSerializer.ts +11 -11
- package/src/events/EventDispatcher.ts +127 -127
- package/src/events/EventSerializer.ts +4 -4
- package/src/events/IEventProcessor.ts +8 -8
- package/src/events/IEventQueue.ts +16 -16
- package/src/events/IEventSender.ts +13 -13
- package/src/events/NullEventProcessor.ts +15 -15
- package/src/events/event.ts +129 -129
- package/src/events/index.ts +11 -11
- package/src/index.ts +21 -21
- package/src/integrations/TestLogger.ts +24 -24
- package/src/integrations/index.ts +1 -1
- package/src/integrations/test_data/FlagBuilder.ts +59 -59
- package/src/integrations/test_data/TestData.ts +57 -57
- package/src/integrations/test_data/TestDataSynchronizer.ts +49 -49
- package/src/integrations/test_data/index.ts +4 -4
- package/src/logging/BasicLogger.ts +108 -108
- package/src/logging/IBasicLoggerOptions.ts +46 -46
- package/src/logging/ILogger.ts +49 -49
- package/src/logging/LogLevel.ts +8 -8
- package/src/logging/SafeLogger.ts +69 -69
- package/src/logging/format.ts +154 -154
- package/src/logging/index.ts +5 -5
- package/src/options/ClientContext.ts +39 -39
- package/src/options/IClientContext.ts +53 -53
- package/src/options/IOptions.ts +123 -123
- package/src/options/IUser.ts +6 -6
- package/src/options/IValidatedOptions.ts +29 -29
- package/src/options/OptionMessages.ts +35 -35
- package/src/options/UserBuilder.ts +35 -35
- package/src/options/Validators.ts +300 -300
- package/src/options/index.ts +7 -7
- package/src/platform/IInfo.ts +102 -102
- package/src/platform/IPlatform.ts +20 -20
- package/src/platform/IStore.ts +112 -112
- package/src/platform/IWebSocket.ts +22 -22
- package/src/platform/browser/BrowserInfo.ts +24 -24
- package/src/platform/browser/BrowserPlatform.ts +19 -19
- package/src/platform/browser/BrowserRequests.ts +6 -6
- package/src/platform/browser/BrowserWebSocket.ts +147 -147
- package/src/platform/browser/FbClient.ts +65 -65
- package/src/platform/browser/LocalStorageStore.ts +59 -59
- package/src/platform/index.ts +11 -11
- package/src/platform/requests.ts +76 -76
- package/src/store/BaseStore.ts +125 -125
- package/src/store/DataKinds.ts +6 -6
- package/src/store/IDataSourceUpdates.ts +68 -68
- package/src/store/InMemoryStore.ts +36 -36
- package/src/store/index.ts +5 -5
- package/src/store/serialization.ts +52 -52
- package/src/store/store.ts +37 -37
- package/src/utils/Emits.ts +75 -75
- package/src/utils/EventEmitter.ts +128 -128
- package/src/utils/IEventEmitter.ts +14 -14
- package/src/utils/Regex.ts +21 -21
- package/src/utils/ValueConverters.ts +55 -55
- package/src/utils/canonicalizeUri.ts +3 -3
- package/src/utils/debounce.ts +33 -33
- package/src/utils/http.ts +40 -40
- package/src/utils/index.ts +5 -5
- package/src/utils/isNullOrUndefined.ts +2 -2
- package/src/utils/serializeUser.ts +27 -27
- package/src/utils/sleep.ts +5 -5
- package/src/version.ts +1 -1
- package/dist/umd/featbit-js-client-sdk-3.0.13.js.map +0 -1
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { ILogger } from "./ILogger";
|
|
2
|
-
import { TypeValidators } from "../options/Validators";
|
|
3
|
-
|
|
4
|
-
const loggerRequirements = {
|
|
5
|
-
error: TypeValidators.Function,
|
|
6
|
-
warn: TypeValidators.Function,
|
|
7
|
-
info: TypeValidators.Function,
|
|
8
|
-
debug: TypeValidators.Function,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The safeLogger logic exists because we allow the application to pass in a custom logger, but
|
|
13
|
-
* there is no guarantee that the logger works correctly and if it ever throws exceptions there
|
|
14
|
-
* could be serious consequences (e.g. an uncaught exception within an error event handler, due
|
|
15
|
-
* to the SDK trying to log the error, can terminate the application). An exception could result
|
|
16
|
-
* from faulty logic in the logger implementation, or it could be that this is not a logger at
|
|
17
|
-
* all but some other kind of object; the former is handled by a catch block that logs an error
|
|
18
|
-
* message to the SDK's default logger, and we can at least partly guard against the latter by
|
|
19
|
-
* checking for the presence of required methods at configuration time.
|
|
20
|
-
*/
|
|
21
|
-
export class SafeLogger implements ILogger {
|
|
22
|
-
private logger: ILogger;
|
|
23
|
-
|
|
24
|
-
private fallback: ILogger;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Construct a safe logger with the specified logger.
|
|
28
|
-
* @param logger The logger to use.
|
|
29
|
-
* @param fallback A fallback logger to use in case an issue is encountered using
|
|
30
|
-
* the provided logger.
|
|
31
|
-
*/
|
|
32
|
-
constructor(logger: ILogger, fallback: ILogger) {
|
|
33
|
-
Object.entries(loggerRequirements).forEach(([level, validator]) => {
|
|
34
|
-
if (!validator.is((logger as any)[level])) {
|
|
35
|
-
throw new Error(`Provided logger instance must support logger.${ level }(...) method`);
|
|
36
|
-
// Note that the SDK normally does not throw exceptions to the application, but that rule
|
|
37
|
-
// does not apply to FbClientNode.init() which will throw an exception if the parameters are so
|
|
38
|
-
// invalid that we cannot proceed with creating the client. An invalid logger meets those
|
|
39
|
-
// criteria since the SDK calls the logger during nearly all of its operations.
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
this.logger = logger;
|
|
43
|
-
this.fallback = fallback;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private log(level: 'error' | 'warn' | 'info' | 'debug', args: any[]) {
|
|
47
|
-
try {
|
|
48
|
-
this.logger[level](...args);
|
|
49
|
-
} catch {
|
|
50
|
-
// If all else fails do not break.
|
|
51
|
-
this.fallback[level](...args);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
error(...args: any[]): void {
|
|
56
|
-
this.log('error', args);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
warn(...args: any[]): void {
|
|
60
|
-
this.log('warn', args);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
info(...args: any[]): void {
|
|
64
|
-
this.log('info', args);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
debug(...args: any[]): void {
|
|
68
|
-
this.log('debug', args);
|
|
69
|
-
}
|
|
1
|
+
import { ILogger } from "./ILogger";
|
|
2
|
+
import { TypeValidators } from "../options/Validators";
|
|
3
|
+
|
|
4
|
+
const loggerRequirements = {
|
|
5
|
+
error: TypeValidators.Function,
|
|
6
|
+
warn: TypeValidators.Function,
|
|
7
|
+
info: TypeValidators.Function,
|
|
8
|
+
debug: TypeValidators.Function,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The safeLogger logic exists because we allow the application to pass in a custom logger, but
|
|
13
|
+
* there is no guarantee that the logger works correctly and if it ever throws exceptions there
|
|
14
|
+
* could be serious consequences (e.g. an uncaught exception within an error event handler, due
|
|
15
|
+
* to the SDK trying to log the error, can terminate the application). An exception could result
|
|
16
|
+
* from faulty logic in the logger implementation, or it could be that this is not a logger at
|
|
17
|
+
* all but some other kind of object; the former is handled by a catch block that logs an error
|
|
18
|
+
* message to the SDK's default logger, and we can at least partly guard against the latter by
|
|
19
|
+
* checking for the presence of required methods at configuration time.
|
|
20
|
+
*/
|
|
21
|
+
export class SafeLogger implements ILogger {
|
|
22
|
+
private logger: ILogger;
|
|
23
|
+
|
|
24
|
+
private fallback: ILogger;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Construct a safe logger with the specified logger.
|
|
28
|
+
* @param logger The logger to use.
|
|
29
|
+
* @param fallback A fallback logger to use in case an issue is encountered using
|
|
30
|
+
* the provided logger.
|
|
31
|
+
*/
|
|
32
|
+
constructor(logger: ILogger, fallback: ILogger) {
|
|
33
|
+
Object.entries(loggerRequirements).forEach(([level, validator]) => {
|
|
34
|
+
if (!validator.is((logger as any)[level])) {
|
|
35
|
+
throw new Error(`Provided logger instance must support logger.${ level }(...) method`);
|
|
36
|
+
// Note that the SDK normally does not throw exceptions to the application, but that rule
|
|
37
|
+
// does not apply to FbClientNode.init() which will throw an exception if the parameters are so
|
|
38
|
+
// invalid that we cannot proceed with creating the client. An invalid logger meets those
|
|
39
|
+
// criteria since the SDK calls the logger during nearly all of its operations.
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
this.logger = logger;
|
|
43
|
+
this.fallback = fallback;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private log(level: 'error' | 'warn' | 'info' | 'debug', args: any[]) {
|
|
47
|
+
try {
|
|
48
|
+
this.logger[level](...args);
|
|
49
|
+
} catch {
|
|
50
|
+
// If all else fails do not break.
|
|
51
|
+
this.fallback[level](...args);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
error(...args: any[]): void {
|
|
56
|
+
this.log('error', args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
warn(...args: any[]): void {
|
|
60
|
+
this.log('warn', args);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
info(...args: any[]): void {
|
|
64
|
+
this.log('info', args);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
debug(...args: any[]): void {
|
|
68
|
+
this.log('debug', args);
|
|
69
|
+
}
|
|
70
70
|
}
|
package/src/logging/format.ts
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
import { TypeValidators } from "../options/Validators";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Attempt to produce a string representation of a value.
|
|
6
|
-
* The format should be roughly comparable to `util.format`
|
|
7
|
-
* aside from object which will be JSON versus the `util.inspect`
|
|
8
|
-
* format.
|
|
9
|
-
* @param val
|
|
10
|
-
* @returns A string representation of the value if possible.
|
|
11
|
-
*/
|
|
12
|
-
function tryStringify(val: any) {
|
|
13
|
-
if (typeof val === 'string') {
|
|
14
|
-
return val;
|
|
15
|
-
}
|
|
16
|
-
if (val === undefined) {
|
|
17
|
-
return 'undefined';
|
|
18
|
-
}
|
|
19
|
-
if (val === null) {
|
|
20
|
-
return 'null';
|
|
21
|
-
}
|
|
22
|
-
if (Object.prototype.hasOwnProperty.call(val, 'toString')) {
|
|
23
|
-
try {
|
|
24
|
-
return val.toString();
|
|
25
|
-
} catch {
|
|
26
|
-
/* Keep going */
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof val === 'bigint') {
|
|
31
|
-
return `${ val }n`;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return JSON.stringify(val);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
if (error instanceof TypeError && error.message.indexOf('circular') >= 0) {
|
|
37
|
-
return '[Circular]';
|
|
38
|
-
}
|
|
39
|
-
return '[Not Stringifiable]';
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Attempt to produce a numeric representation.
|
|
45
|
-
* BigInts have an `n` suffix.
|
|
46
|
-
* @param val
|
|
47
|
-
* @returns The numeric representation or 'NaN' if not numeric.
|
|
48
|
-
*/
|
|
49
|
-
function toNumber(val: any): string {
|
|
50
|
-
// Symbol has to be treated special because it will
|
|
51
|
-
// throw an exception if an attempt is made to convert it.
|
|
52
|
-
if (typeof val === 'symbol') {
|
|
53
|
-
return 'NaN';
|
|
54
|
-
}
|
|
55
|
-
if (typeof val === 'bigint') {
|
|
56
|
-
return `${ val }n`;
|
|
57
|
-
}
|
|
58
|
-
return String(Number(val));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Attempt to produce an integer representation.
|
|
63
|
-
* BigInts have an `n` suffix.
|
|
64
|
-
* @param val
|
|
65
|
-
* @returns The integer representation or 'NaN' if not numeric.
|
|
66
|
-
*/
|
|
67
|
-
function toInt(val: any): string {
|
|
68
|
-
if (typeof val === 'symbol') {
|
|
69
|
-
return 'NaN';
|
|
70
|
-
}
|
|
71
|
-
if (typeof val === 'bigint') {
|
|
72
|
-
return `${ val }n`;
|
|
73
|
-
}
|
|
74
|
-
return String(parseInt(val, 10));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Attempt to produce a float representation.
|
|
79
|
-
* BigInts have an `n` suffix.
|
|
80
|
-
* @param val
|
|
81
|
-
* @returns The integer representation or 'NaN' if not numeric.
|
|
82
|
-
*/
|
|
83
|
-
function toFloat(val: any): string {
|
|
84
|
-
if (typeof val === 'symbol') {
|
|
85
|
-
return 'NaN';
|
|
86
|
-
}
|
|
87
|
-
return String(parseFloat(val));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Based on:
|
|
91
|
-
// https://nodejs.org/api/util.html#utilformatformat-args
|
|
92
|
-
// The result will not match browser exactly, but it should get the
|
|
93
|
-
// right information through.
|
|
94
|
-
const escapes: Record<string, (val: any) => string> = {
|
|
95
|
-
s: (val: any) => tryStringify(val),
|
|
96
|
-
d: (val: any) => toNumber(val),
|
|
97
|
-
i: (val: any) => toInt(val),
|
|
98
|
-
f: (val: any) => toFloat(val),
|
|
99
|
-
j: (val: any) => tryStringify(val),
|
|
100
|
-
o: (val: any) => tryStringify(val),
|
|
101
|
-
O: (val: any) => tryStringify(val),
|
|
102
|
-
c: () => '',
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* A basic formatted for use where `util.format` is not available.
|
|
107
|
-
* This will not be as performant, but it will produce formatted
|
|
108
|
-
* messages.
|
|
109
|
-
*
|
|
110
|
-
* @internal
|
|
111
|
-
*
|
|
112
|
-
* @param args
|
|
113
|
-
* @returns Formatted string.
|
|
114
|
-
*/
|
|
115
|
-
export default function format(...args: any[]): string {
|
|
116
|
-
const formatString = args.shift();
|
|
117
|
-
if (TypeValidators.String.is(formatString)) {
|
|
118
|
-
let out = '';
|
|
119
|
-
let i = 0;
|
|
120
|
-
while (i < formatString.length) {
|
|
121
|
-
const char = formatString.charAt(i);
|
|
122
|
-
if (char === '%') {
|
|
123
|
-
const nextIndex = i + 1;
|
|
124
|
-
if (nextIndex < formatString.length) {
|
|
125
|
-
const nextChar = formatString.charAt(i + 1);
|
|
126
|
-
if (nextChar in escapes && args.length) {
|
|
127
|
-
const value = args.shift();
|
|
128
|
-
// This rule is for math.
|
|
129
|
-
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
130
|
-
out += escapes[nextChar]?.(value);
|
|
131
|
-
} else if (nextChar === '%') {
|
|
132
|
-
out += '%';
|
|
133
|
-
} else {
|
|
134
|
-
out += `%${ nextChar }`;
|
|
135
|
-
}
|
|
136
|
-
i += 2;
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
out += char;
|
|
140
|
-
i += 1;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// If there are any args left after we exhaust the format string
|
|
144
|
-
// then just stick those on the end.
|
|
145
|
-
if (args.length) {
|
|
146
|
-
if (out.length) {
|
|
147
|
-
out += ' ';
|
|
148
|
-
}
|
|
149
|
-
out += args.map(tryStringify).join(' ');
|
|
150
|
-
}
|
|
151
|
-
return out;
|
|
152
|
-
}
|
|
153
|
-
return args.map(tryStringify).join(' ');
|
|
154
|
-
}
|
|
1
|
+
import { TypeValidators } from "../options/Validators";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Attempt to produce a string representation of a value.
|
|
6
|
+
* The format should be roughly comparable to `util.format`
|
|
7
|
+
* aside from object which will be JSON versus the `util.inspect`
|
|
8
|
+
* format.
|
|
9
|
+
* @param val
|
|
10
|
+
* @returns A string representation of the value if possible.
|
|
11
|
+
*/
|
|
12
|
+
function tryStringify(val: any) {
|
|
13
|
+
if (typeof val === 'string') {
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
if (val === undefined) {
|
|
17
|
+
return 'undefined';
|
|
18
|
+
}
|
|
19
|
+
if (val === null) {
|
|
20
|
+
return 'null';
|
|
21
|
+
}
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(val, 'toString')) {
|
|
23
|
+
try {
|
|
24
|
+
return val.toString();
|
|
25
|
+
} catch {
|
|
26
|
+
/* Keep going */
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof val === 'bigint') {
|
|
31
|
+
return `${ val }n`;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(val);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof TypeError && error.message.indexOf('circular') >= 0) {
|
|
37
|
+
return '[Circular]';
|
|
38
|
+
}
|
|
39
|
+
return '[Not Stringifiable]';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Attempt to produce a numeric representation.
|
|
45
|
+
* BigInts have an `n` suffix.
|
|
46
|
+
* @param val
|
|
47
|
+
* @returns The numeric representation or 'NaN' if not numeric.
|
|
48
|
+
*/
|
|
49
|
+
function toNumber(val: any): string {
|
|
50
|
+
// Symbol has to be treated special because it will
|
|
51
|
+
// throw an exception if an attempt is made to convert it.
|
|
52
|
+
if (typeof val === 'symbol') {
|
|
53
|
+
return 'NaN';
|
|
54
|
+
}
|
|
55
|
+
if (typeof val === 'bigint') {
|
|
56
|
+
return `${ val }n`;
|
|
57
|
+
}
|
|
58
|
+
return String(Number(val));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Attempt to produce an integer representation.
|
|
63
|
+
* BigInts have an `n` suffix.
|
|
64
|
+
* @param val
|
|
65
|
+
* @returns The integer representation or 'NaN' if not numeric.
|
|
66
|
+
*/
|
|
67
|
+
function toInt(val: any): string {
|
|
68
|
+
if (typeof val === 'symbol') {
|
|
69
|
+
return 'NaN';
|
|
70
|
+
}
|
|
71
|
+
if (typeof val === 'bigint') {
|
|
72
|
+
return `${ val }n`;
|
|
73
|
+
}
|
|
74
|
+
return String(parseInt(val, 10));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Attempt to produce a float representation.
|
|
79
|
+
* BigInts have an `n` suffix.
|
|
80
|
+
* @param val
|
|
81
|
+
* @returns The integer representation or 'NaN' if not numeric.
|
|
82
|
+
*/
|
|
83
|
+
function toFloat(val: any): string {
|
|
84
|
+
if (typeof val === 'symbol') {
|
|
85
|
+
return 'NaN';
|
|
86
|
+
}
|
|
87
|
+
return String(parseFloat(val));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Based on:
|
|
91
|
+
// https://nodejs.org/api/util.html#utilformatformat-args
|
|
92
|
+
// The result will not match browser exactly, but it should get the
|
|
93
|
+
// right information through.
|
|
94
|
+
const escapes: Record<string, (val: any) => string> = {
|
|
95
|
+
s: (val: any) => tryStringify(val),
|
|
96
|
+
d: (val: any) => toNumber(val),
|
|
97
|
+
i: (val: any) => toInt(val),
|
|
98
|
+
f: (val: any) => toFloat(val),
|
|
99
|
+
j: (val: any) => tryStringify(val),
|
|
100
|
+
o: (val: any) => tryStringify(val),
|
|
101
|
+
O: (val: any) => tryStringify(val),
|
|
102
|
+
c: () => '',
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A basic formatted for use where `util.format` is not available.
|
|
107
|
+
* This will not be as performant, but it will produce formatted
|
|
108
|
+
* messages.
|
|
109
|
+
*
|
|
110
|
+
* @internal
|
|
111
|
+
*
|
|
112
|
+
* @param args
|
|
113
|
+
* @returns Formatted string.
|
|
114
|
+
*/
|
|
115
|
+
export default function format(...args: any[]): string {
|
|
116
|
+
const formatString = args.shift();
|
|
117
|
+
if (TypeValidators.String.is(formatString)) {
|
|
118
|
+
let out = '';
|
|
119
|
+
let i = 0;
|
|
120
|
+
while (i < formatString.length) {
|
|
121
|
+
const char = formatString.charAt(i);
|
|
122
|
+
if (char === '%') {
|
|
123
|
+
const nextIndex = i + 1;
|
|
124
|
+
if (nextIndex < formatString.length) {
|
|
125
|
+
const nextChar = formatString.charAt(i + 1);
|
|
126
|
+
if (nextChar in escapes && args.length) {
|
|
127
|
+
const value = args.shift();
|
|
128
|
+
// This rule is for math.
|
|
129
|
+
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
130
|
+
out += escapes[nextChar]?.(value);
|
|
131
|
+
} else if (nextChar === '%') {
|
|
132
|
+
out += '%';
|
|
133
|
+
} else {
|
|
134
|
+
out += `%${ nextChar }`;
|
|
135
|
+
}
|
|
136
|
+
i += 2;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
out += char;
|
|
140
|
+
i += 1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// If there are any args left after we exhaust the format string
|
|
144
|
+
// then just stick those on the end.
|
|
145
|
+
if (args.length) {
|
|
146
|
+
if (out.length) {
|
|
147
|
+
out += ' ';
|
|
148
|
+
}
|
|
149
|
+
out += args.map(tryStringify).join(' ');
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
return args.map(tryStringify).join(' ');
|
|
154
|
+
}
|
package/src/logging/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './BasicLogger';
|
|
2
|
-
export * from './format';
|
|
3
|
-
export * from './IBasicLoggerOptions';
|
|
4
|
-
export * from './ILogger';
|
|
5
|
-
export * from './LogLevel';
|
|
1
|
+
export * from './BasicLogger';
|
|
2
|
+
export * from './format';
|
|
3
|
+
export * from './IBasicLoggerOptions';
|
|
4
|
+
export * from './ILogger';
|
|
5
|
+
export * from './LogLevel';
|
|
6
6
|
export * from './SafeLogger';
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { ILogger } from "../logging/ILogger";
|
|
2
|
-
import { IPlatform } from "../platform/IPlatform";
|
|
3
|
-
import { IClientContext } from "./IClientContext";
|
|
4
|
-
import { IUser } from "./IUser";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The client context provides basic configuration and platform support which are required
|
|
8
|
-
* when building SDK components.
|
|
9
|
-
*/
|
|
10
|
-
export default class ClientContext implements IClientContext {
|
|
11
|
-
flushInterval: number;
|
|
12
|
-
maxEventsInQueue: number;
|
|
13
|
-
offline: boolean;
|
|
14
|
-
logger: ILogger;
|
|
15
|
-
eventsUri: string;
|
|
16
|
-
pollingUri: string;
|
|
17
|
-
streamingUri: string;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
public readonly sdkKey: string,
|
|
21
|
-
configuration: {
|
|
22
|
-
logger?: ILogger;
|
|
23
|
-
offline?: boolean;
|
|
24
|
-
flushInterval: number;
|
|
25
|
-
maxEventsInQueue: number;
|
|
26
|
-
streamingUri: string;
|
|
27
|
-
pollingUri: string;
|
|
28
|
-
eventsUri: string;
|
|
29
|
-
},
|
|
30
|
-
public readonly platform: IPlatform,
|
|
31
|
-
) {
|
|
32
|
-
this.logger = configuration.logger!;
|
|
33
|
-
this.offline = configuration.offline!;
|
|
34
|
-
this.flushInterval = configuration.flushInterval;
|
|
35
|
-
this.maxEventsInQueue = configuration.maxEventsInQueue;
|
|
36
|
-
this.streamingUri = configuration.streamingUri;
|
|
37
|
-
this.pollingUri = configuration.pollingUri;
|
|
38
|
-
this.eventsUri = configuration.eventsUri;
|
|
39
|
-
}
|
|
1
|
+
import { ILogger } from "../logging/ILogger";
|
|
2
|
+
import { IPlatform } from "../platform/IPlatform";
|
|
3
|
+
import { IClientContext } from "./IClientContext";
|
|
4
|
+
import { IUser } from "./IUser";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The client context provides basic configuration and platform support which are required
|
|
8
|
+
* when building SDK components.
|
|
9
|
+
*/
|
|
10
|
+
export default class ClientContext implements IClientContext {
|
|
11
|
+
flushInterval: number;
|
|
12
|
+
maxEventsInQueue: number;
|
|
13
|
+
offline: boolean;
|
|
14
|
+
logger: ILogger;
|
|
15
|
+
eventsUri: string;
|
|
16
|
+
pollingUri: string;
|
|
17
|
+
streamingUri: string;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
public readonly sdkKey: string,
|
|
21
|
+
configuration: {
|
|
22
|
+
logger?: ILogger;
|
|
23
|
+
offline?: boolean;
|
|
24
|
+
flushInterval: number;
|
|
25
|
+
maxEventsInQueue: number;
|
|
26
|
+
streamingUri: string;
|
|
27
|
+
pollingUri: string;
|
|
28
|
+
eventsUri: string;
|
|
29
|
+
},
|
|
30
|
+
public readonly platform: IPlatform,
|
|
31
|
+
) {
|
|
32
|
+
this.logger = configuration.logger!;
|
|
33
|
+
this.offline = configuration.offline!;
|
|
34
|
+
this.flushInterval = configuration.flushInterval;
|
|
35
|
+
this.maxEventsInQueue = configuration.maxEventsInQueue;
|
|
36
|
+
this.streamingUri = configuration.streamingUri;
|
|
37
|
+
this.pollingUri = configuration.pollingUri;
|
|
38
|
+
this.eventsUri = configuration.eventsUri;
|
|
39
|
+
}
|
|
40
40
|
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { ILogger } from "../logging/ILogger";
|
|
2
|
-
import { IPlatform } from "../platform/IPlatform";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Factory methods receive this class as a parameter.
|
|
6
|
-
*
|
|
7
|
-
* Its public properties provide information about the SDK configuration and environment. The SDK
|
|
8
|
-
* may also include non-public properties that are relevant only when creating one of the built-in
|
|
9
|
-
* component types and are not accessible to custom components.
|
|
10
|
-
*/
|
|
11
|
-
export interface IClientContext {
|
|
12
|
-
|
|
13
|
-
logger?: ILogger;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* True if the SDK was configured to be completely offline.
|
|
17
|
-
*/
|
|
18
|
-
offline?: boolean;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The configured SDK key.
|
|
22
|
-
*/
|
|
23
|
-
sdkKey: string;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The base URI of the data-sync service
|
|
27
|
-
*/
|
|
28
|
-
streamingUri: string;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The base URI of the polling service
|
|
32
|
-
*/
|
|
33
|
-
pollingUri: string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The base URI of the event service
|
|
37
|
-
*/
|
|
38
|
-
eventsUri: string;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The interval in between flushes of events queue, in milliseconds.
|
|
42
|
-
*/
|
|
43
|
-
flushInterval: number;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The max number of events in the events queue.
|
|
47
|
-
*/
|
|
48
|
-
maxEventsInQueue: number;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Interfaces providing platform specific information and functionality.
|
|
52
|
-
*/
|
|
53
|
-
platform: IPlatform;
|
|
1
|
+
import { ILogger } from "../logging/ILogger";
|
|
2
|
+
import { IPlatform } from "../platform/IPlatform";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Factory methods receive this class as a parameter.
|
|
6
|
+
*
|
|
7
|
+
* Its public properties provide information about the SDK configuration and environment. The SDK
|
|
8
|
+
* may also include non-public properties that are relevant only when creating one of the built-in
|
|
9
|
+
* component types and are not accessible to custom components.
|
|
10
|
+
*/
|
|
11
|
+
export interface IClientContext {
|
|
12
|
+
|
|
13
|
+
logger?: ILogger;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* True if the SDK was configured to be completely offline.
|
|
17
|
+
*/
|
|
18
|
+
offline?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The configured SDK key.
|
|
22
|
+
*/
|
|
23
|
+
sdkKey: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The base URI of the data-sync service
|
|
27
|
+
*/
|
|
28
|
+
streamingUri: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The base URI of the polling service
|
|
32
|
+
*/
|
|
33
|
+
pollingUri: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The base URI of the event service
|
|
37
|
+
*/
|
|
38
|
+
eventsUri: string;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The interval in between flushes of events queue, in milliseconds.
|
|
42
|
+
*/
|
|
43
|
+
flushInterval: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The max number of events in the events queue.
|
|
47
|
+
*/
|
|
48
|
+
maxEventsInQueue: number;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Interfaces providing platform specific information and functionality.
|
|
52
|
+
*/
|
|
53
|
+
platform: IPlatform;
|
|
54
54
|
}
|