@launchdarkly/js-sdk-common 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/api/context/LDContext.d.ts +16 -1
- package/dist/cjs/api/context/LDContext.d.ts.map +1 -1
- package/dist/cjs/api/context/LDContextCommon.d.ts +3 -0
- package/dist/cjs/api/context/LDContextCommon.d.ts.map +1 -1
- package/dist/cjs/api/context/LDUser.d.ts +0 -4
- package/dist/cjs/api/context/LDUser.d.ts.map +1 -1
- package/dist/cjs/api/logging/BasicLoggerOptions.d.ts +7 -4
- package/dist/cjs/api/logging/BasicLoggerOptions.d.ts.map +1 -1
- package/dist/cjs/api/platform/AutoEnv.d.ts +0 -2
- package/dist/cjs/api/platform/AutoEnv.d.ts.map +1 -1
- package/dist/cjs/api/platform/EventSource.d.ts +1 -1
- package/dist/cjs/api/platform/EventSource.d.ts.map +1 -1
- package/dist/cjs/datasource/errors.d.ts +1 -0
- package/dist/cjs/datasource/errors.d.ts.map +1 -1
- package/dist/cjs/datasource/index.d.ts +2 -2
- package/dist/cjs/datasource/index.d.ts.map +1 -1
- package/dist/cjs/index.cjs +170 -104
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/internal/fdv2/index.d.ts +3 -0
- package/dist/cjs/internal/fdv2/index.d.ts.map +1 -0
- package/dist/cjs/internal/fdv2/payloadReader.d.ts +58 -0
- package/dist/cjs/internal/fdv2/payloadReader.d.ts.map +1 -0
- package/dist/cjs/internal/fdv2/proto.d.ts +30 -0
- package/dist/cjs/internal/fdv2/proto.d.ts.map +1 -0
- package/dist/cjs/internal/index.d.ts +1 -1
- package/dist/cjs/internal/index.d.ts.map +1 -1
- package/dist/cjs/logging/BasicLogger.d.ts +1 -1
- package/dist/cjs/logging/BasicLogger.d.ts.map +1 -1
- package/dist/esm/api/context/LDContext.d.ts +16 -1
- package/dist/esm/api/context/LDContext.d.ts.map +1 -1
- package/dist/esm/api/context/LDContextCommon.d.ts +3 -0
- package/dist/esm/api/context/LDContextCommon.d.ts.map +1 -1
- package/dist/esm/api/context/LDUser.d.ts +0 -4
- package/dist/esm/api/context/LDUser.d.ts.map +1 -1
- package/dist/esm/api/logging/BasicLoggerOptions.d.ts +7 -4
- package/dist/esm/api/logging/BasicLoggerOptions.d.ts.map +1 -1
- package/dist/esm/api/platform/AutoEnv.d.ts +0 -2
- package/dist/esm/api/platform/AutoEnv.d.ts.map +1 -1
- package/dist/esm/api/platform/EventSource.d.ts +1 -1
- package/dist/esm/api/platform/EventSource.d.ts.map +1 -1
- package/dist/esm/datasource/errors.d.ts +1 -0
- package/dist/esm/datasource/errors.d.ts.map +1 -1
- package/dist/esm/datasource/index.d.ts +2 -2
- package/dist/esm/datasource/index.d.ts.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +170 -104
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internal/fdv2/index.d.ts +3 -0
- package/dist/esm/internal/fdv2/index.d.ts.map +1 -0
- package/dist/esm/internal/fdv2/payloadReader.d.ts +58 -0
- package/dist/esm/internal/fdv2/payloadReader.d.ts.map +1 -0
- package/dist/esm/internal/fdv2/proto.d.ts +30 -0
- package/dist/esm/internal/fdv2/proto.d.ts.map +1 -0
- package/dist/esm/internal/index.d.ts +1 -1
- package/dist/esm/internal/index.d.ts.map +1 -1
- package/dist/esm/logging/BasicLogger.d.ts +1 -1
- package/dist/esm/logging/BasicLogger.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/internal/stream/StreamingProcessor.d.ts +0 -39
- package/dist/cjs/internal/stream/StreamingProcessor.d.ts.map +0 -1
- package/dist/cjs/internal/stream/index.d.ts +0 -5
- package/dist/cjs/internal/stream/index.d.ts.map +0 -1
- package/dist/cjs/internal/stream/types.d.ts +0 -3
- package/dist/cjs/internal/stream/types.d.ts.map +0 -1
- package/dist/esm/internal/stream/StreamingProcessor.d.ts +0 -39
- package/dist/esm/internal/stream/StreamingProcessor.d.ts.map +0 -1
- package/dist/esm/internal/stream/index.d.ts +0 -5
- package/dist/esm/internal/stream/index.d.ts.map +0 -1
- package/dist/esm/internal/stream/types.d.ts +0 -3
- package/dist/esm/internal/stream/types.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoEnv.d.ts","sourceRoot":"","sources":["../../../src/api/platform/AutoEnv.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"AutoEnv.d.ts","sourceRoot":"","sources":["../../../src/api/platform/AutoEnv.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,oBAAY,iBAAiB;IAC3B,QAAQ,IAAA;IACR,OAAO,IAAA;CACR;AAED,UAAU,aAAa;IACrB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,QAAS,SAAQ,aAAa;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE;QACH;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventSource.d.ts","sourceRoot":"","sources":["../../../src/api/platform/EventSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"EventSource.d.ts","sourceRoot":"","sources":["../../../src/api/platform/EventSource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,KAAK,IAAI,CAAC;AAC7D,MAAM,MAAM,qBAAqB,GAAG;IAClC,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IACvC,WAAW,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACzD,MAAM,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAE/D,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IACjE,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,OAAO,CAAC;IACjD,uBAAuB,EAAE,MAAM,CAAC;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,wBAAwB,EAAE,MAAM,CAAC;CAClC"}
|
|
@@ -14,4 +14,5 @@ export declare class LDStreamingError extends Error {
|
|
|
14
14
|
readonly recoverable: boolean;
|
|
15
15
|
constructor(kind: DataSourceErrorKind, message: string, code?: number, recoverable?: boolean);
|
|
16
16
|
}
|
|
17
|
+
export type StreamingErrorHandler = (err: LDStreamingError) => void;
|
|
17
18
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/datasource/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,mBAAmB,CAAC;IAC1C,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAEzB,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO;CAO5F;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,mBAAmB,CAAC;IAC1C,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAEzB,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO;CAO1F"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/datasource/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,mBAAmB,CAAC;IAC1C,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAEzB,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO;CAO5F;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,mBAAmB,CAAC;IAC1C,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAEzB,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO;CAO1F;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DataSourceErrorKind } from './DataSourceErrorKinds';
|
|
2
|
-
import { LDFileDataSourceError, LDPollingError, LDStreamingError } from './errors';
|
|
3
|
-
export { DataSourceErrorKind, LDFileDataSourceError, LDPollingError, LDStreamingError };
|
|
2
|
+
import { LDFileDataSourceError, LDPollingError, LDStreamingError, StreamingErrorHandler } from './errors';
|
|
3
|
+
export { DataSourceErrorKind, LDFileDataSourceError, LDPollingError, LDStreamingError, StreamingErrorHandler, };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datasource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datasource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,GACtB,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import AttributeReference from './AttributeReference';
|
|
2
2
|
import Context from './Context';
|
|
3
3
|
import ContextFilter from './ContextFilter';
|
|
4
|
-
import { DataSourceErrorKind, LDFileDataSourceError, LDPollingError, LDStreamingError } from './datasource';
|
|
4
|
+
import { DataSourceErrorKind, LDFileDataSourceError, LDPollingError, LDStreamingError, StreamingErrorHandler } from './datasource';
|
|
5
5
|
export * from './api';
|
|
6
6
|
export * from './validators';
|
|
7
7
|
export * from './logging';
|
|
@@ -9,5 +9,5 @@ export * from './options';
|
|
|
9
9
|
export * from './utils';
|
|
10
10
|
export * as internal from './internal';
|
|
11
11
|
export * from './errors';
|
|
12
|
-
export { AttributeReference, Context, ContextFilter, DataSourceErrorKind, LDPollingError, LDStreamingError, LDFileDataSourceError, };
|
|
12
|
+
export { AttributeReference, Context, ContextFilter, DataSourceErrorKind, LDPollingError, LDStreamingError, StreamingErrorHandler, LDFileDataSourceError, };
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AACtD,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAEtB,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,cAAc,UAAU,CAAC;AAEzB,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,GACtB,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -858,8 +858,6 @@ class LDStreamingError extends Error {
|
|
|
858
858
|
* model, operating system, locale, and so on. We recommend enabling this when you configure the SDK. To learn more,
|
|
859
859
|
* read [Automatic environment attributes](https://docs.launchdarkly.com/sdk/features/environment-attributes).
|
|
860
860
|
* for more documentation.
|
|
861
|
-
*
|
|
862
|
-
* The default is disabled.
|
|
863
861
|
*/
|
|
864
862
|
var AutoEnvAttributes;
|
|
865
863
|
(function (AutoEnvAttributes) {
|
|
@@ -1037,14 +1035,15 @@ function format(...args) {
|
|
|
1037
1035
|
return args.map(tryStringify).join(' ');
|
|
1038
1036
|
}
|
|
1039
1037
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1038
|
+
var LogPriority;
|
|
1039
|
+
(function (LogPriority) {
|
|
1040
|
+
LogPriority[LogPriority["debug"] = 0] = "debug";
|
|
1041
|
+
LogPriority[LogPriority["info"] = 1] = "info";
|
|
1042
|
+
LogPriority[LogPriority["warn"] = 2] = "warn";
|
|
1043
|
+
LogPriority[LogPriority["error"] = 3] = "error";
|
|
1044
|
+
LogPriority[LogPriority["none"] = 4] = "none";
|
|
1045
|
+
})(LogPriority || (LogPriority = {}));
|
|
1046
|
+
const LEVEL_NAMES = ['debug', 'info', 'warn', 'error', 'none'];
|
|
1048
1047
|
/**
|
|
1049
1048
|
* A basic logger which handles filtering by level.
|
|
1050
1049
|
*
|
|
@@ -1068,9 +1067,24 @@ class BasicLogger {
|
|
|
1068
1067
|
constructor(options) {
|
|
1069
1068
|
this._logLevel = LogPriority[options.level ?? 'info'] ?? LogPriority.info;
|
|
1070
1069
|
this._name = options.name ?? 'LaunchDarkly';
|
|
1071
|
-
// eslint-disable-next-line no-console
|
|
1072
|
-
this._destination = options.destination;
|
|
1073
1070
|
this._formatter = options.formatter;
|
|
1071
|
+
if (typeof options.destination === 'object') {
|
|
1072
|
+
this._destinations = {
|
|
1073
|
+
[LogPriority.debug]: options.destination.debug,
|
|
1074
|
+
[LogPriority.info]: options.destination.info,
|
|
1075
|
+
[LogPriority.warn]: options.destination.warn,
|
|
1076
|
+
[LogPriority.error]: options.destination.error,
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
else if (typeof options.destination === 'function') {
|
|
1080
|
+
const { destination } = options;
|
|
1081
|
+
this._destinations = {
|
|
1082
|
+
[LogPriority.debug]: destination,
|
|
1083
|
+
[LogPriority.info]: destination,
|
|
1084
|
+
[LogPriority.warn]: destination,
|
|
1085
|
+
[LogPriority.error]: destination,
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1074
1088
|
}
|
|
1075
1089
|
_tryFormat(...args) {
|
|
1076
1090
|
try {
|
|
@@ -1084,9 +1098,9 @@ class BasicLogger {
|
|
|
1084
1098
|
return format(...args);
|
|
1085
1099
|
}
|
|
1086
1100
|
}
|
|
1087
|
-
_tryWrite(msg) {
|
|
1101
|
+
_tryWrite(destination, msg) {
|
|
1088
1102
|
try {
|
|
1089
|
-
|
|
1103
|
+
destination(msg);
|
|
1090
1104
|
}
|
|
1091
1105
|
catch {
|
|
1092
1106
|
// eslint-disable-next-line no-console
|
|
@@ -1095,10 +1109,11 @@ class BasicLogger {
|
|
|
1095
1109
|
}
|
|
1096
1110
|
_log(level, args) {
|
|
1097
1111
|
if (level >= this._logLevel) {
|
|
1098
|
-
const prefix = `${
|
|
1112
|
+
const prefix = `${LEVEL_NAMES[level]}: [${this._name}]`;
|
|
1099
1113
|
try {
|
|
1100
|
-
|
|
1101
|
-
|
|
1114
|
+
const destination = this._destinations?.[level];
|
|
1115
|
+
if (destination) {
|
|
1116
|
+
this._tryWrite(destination, `${prefix} ${this._tryFormat(...args)}`);
|
|
1102
1117
|
}
|
|
1103
1118
|
else {
|
|
1104
1119
|
// `console.error` has its own formatter.
|
|
@@ -2309,104 +2324,155 @@ class EventFactoryBase {
|
|
|
2309
2324
|
}
|
|
2310
2325
|
}
|
|
2311
2326
|
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
class StreamingProcessor {
|
|
2319
|
-
constructor(clientContext, streamUriPath, parameters, _listeners, baseHeaders, _diagnosticsManager, _errorHandler, _streamInitialReconnectDelay = 1) {
|
|
2320
|
-
this._listeners = _listeners;
|
|
2321
|
-
this._diagnosticsManager = _diagnosticsManager;
|
|
2322
|
-
this._errorHandler = _errorHandler;
|
|
2323
|
-
this._streamInitialReconnectDelay = _streamInitialReconnectDelay;
|
|
2324
|
-
const { basicConfiguration, platform } = clientContext;
|
|
2325
|
-
const { logger } = basicConfiguration;
|
|
2326
|
-
const { requests } = platform;
|
|
2327
|
-
this._headers = { ...baseHeaders };
|
|
2328
|
-
this._logger = logger;
|
|
2329
|
-
this._requests = requests;
|
|
2330
|
-
this._streamUri = getStreamingUri(basicConfiguration.serviceEndpoints, streamUriPath, parameters);
|
|
2331
|
-
}
|
|
2332
|
-
_logConnectionStarted() {
|
|
2333
|
-
this._connectionAttemptStartTime = Date.now();
|
|
2334
|
-
}
|
|
2335
|
-
_logConnectionResult(success) {
|
|
2336
|
-
if (this._connectionAttemptStartTime && this._diagnosticsManager) {
|
|
2337
|
-
this._diagnosticsManager.recordStreamInit(this._connectionAttemptStartTime, !success, Date.now() - this._connectionAttemptStartTime);
|
|
2338
|
-
}
|
|
2339
|
-
this._connectionAttemptStartTime = undefined;
|
|
2340
|
-
}
|
|
2327
|
+
/**
|
|
2328
|
+
* A FDv2 PayloadReader can be used to parse payloads from a stream of FDv2 events. It will send payloads
|
|
2329
|
+
* to the PayloadListeners as the payloads are received. Invalid series of events may be dropped silently,
|
|
2330
|
+
* but the payload reader will continue to operate.
|
|
2331
|
+
*/
|
|
2332
|
+
class PayloadReader {
|
|
2341
2333
|
/**
|
|
2342
|
-
*
|
|
2343
|
-
* diagnostics and logging logic.
|
|
2334
|
+
* Creates a PayloadReader
|
|
2344
2335
|
*
|
|
2345
|
-
* @param
|
|
2346
|
-
* @
|
|
2347
|
-
*
|
|
2348
|
-
* @
|
|
2336
|
+
* @param eventStream event stream of FDv2 events
|
|
2337
|
+
* @param _objProcessors defines object processors for each object kind.
|
|
2338
|
+
* @param _errorHandler that will be called with errors as they are encountered
|
|
2339
|
+
* @param _logger for logging
|
|
2349
2340
|
*/
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
this.
|
|
2358
|
-
this.
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2341
|
+
constructor(eventStream, _objProcessors, _errorHandler, _logger) {
|
|
2342
|
+
this._objProcessors = _objProcessors;
|
|
2343
|
+
this._errorHandler = _errorHandler;
|
|
2344
|
+
this._logger = _logger;
|
|
2345
|
+
this._listeners = [];
|
|
2346
|
+
this._tempId = undefined;
|
|
2347
|
+
this._tempBasis = undefined;
|
|
2348
|
+
this._tempUpdates = [];
|
|
2349
|
+
this._processServerIntent = (data) => {
|
|
2350
|
+
// clear state in prep for handling data
|
|
2351
|
+
this._resetState();
|
|
2352
|
+
// if there's no payloads, return
|
|
2353
|
+
if (!data.payloads.length) {
|
|
2354
|
+
return;
|
|
2355
|
+
}
|
|
2356
|
+
// at the time of writing this, it was agreed upon that SDKs could assume exactly 1 element in this list. In the future, a negotiation of protocol version will be required to remove this assumption.
|
|
2357
|
+
const payload = data.payloads[0];
|
|
2358
|
+
switch (payload?.code) {
|
|
2359
|
+
case 'xfer-full':
|
|
2360
|
+
this._tempBasis = true;
|
|
2361
|
+
break;
|
|
2362
|
+
case 'xfer-changes':
|
|
2363
|
+
case 'none':
|
|
2364
|
+
this._tempBasis = false;
|
|
2365
|
+
break;
|
|
2366
|
+
default:
|
|
2367
|
+
// unrecognized intent code, return
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
this._tempId = payload?.id;
|
|
2375
2371
|
};
|
|
2376
|
-
|
|
2377
|
-
//
|
|
2372
|
+
this._processPutObject = (data) => {
|
|
2373
|
+
// if the following properties haven't been provided by now, we should ignore the event
|
|
2374
|
+
if (!this._tempId || // server intent hasn't been recieved yet.
|
|
2375
|
+
!data.kind ||
|
|
2376
|
+
!data.key ||
|
|
2377
|
+
!data.version ||
|
|
2378
|
+
!data.object) {
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
const obj = this._processObj(data.kind, data.object);
|
|
2382
|
+
if (!obj) {
|
|
2383
|
+
this._logger?.warn(`Unable to prcoess object for kind: '${data.kind}'`);
|
|
2384
|
+
// ignore unrecognized kinds
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
this._tempUpdates.push({
|
|
2388
|
+
kind: data.kind,
|
|
2389
|
+
key: data.key,
|
|
2390
|
+
version: data.version,
|
|
2391
|
+
object: obj,
|
|
2392
|
+
// intentionally omit deleted for this put
|
|
2393
|
+
});
|
|
2378
2394
|
};
|
|
2379
|
-
|
|
2380
|
-
|
|
2395
|
+
this._processDeleteObject = (data) => {
|
|
2396
|
+
// if the following properties haven't been provided by now, we should ignore the event
|
|
2397
|
+
if (!this._tempId || !data.kind || !data.key || !data.version) {
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
this._tempUpdates.push({
|
|
2401
|
+
kind: data.kind,
|
|
2402
|
+
key: data.key,
|
|
2403
|
+
version: data.version,
|
|
2404
|
+
// intentionally omit object for this delete
|
|
2405
|
+
deleted: true,
|
|
2406
|
+
});
|
|
2381
2407
|
};
|
|
2382
|
-
|
|
2383
|
-
|
|
2408
|
+
this._processPayloadTransferred = (data) => {
|
|
2409
|
+
// if the following properties haven't been provided by now, we should reset
|
|
2410
|
+
if (!this._tempId || // server intent hasn't been recieved yet.
|
|
2411
|
+
!data.state ||
|
|
2412
|
+
!data.version ||
|
|
2413
|
+
this._tempBasis === undefined) {
|
|
2414
|
+
this._resetState(); // a reset is best defensive action since payload transferred terminates a payload
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
const payload = {
|
|
2418
|
+
id: this._tempId,
|
|
2419
|
+
version: data.version,
|
|
2420
|
+
state: data.state,
|
|
2421
|
+
basis: this._tempBasis,
|
|
2422
|
+
updates: this._tempUpdates,
|
|
2423
|
+
};
|
|
2424
|
+
this._listeners.forEach((it) => it(payload));
|
|
2425
|
+
this._resetState();
|
|
2384
2426
|
};
|
|
2385
|
-
this.
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2427
|
+
this._processGoodbye = (data) => {
|
|
2428
|
+
this._logger?.info(`Goodbye was received from the LaunchDarkly connection with reason: ${data.reason}.`);
|
|
2429
|
+
this._resetState();
|
|
2430
|
+
};
|
|
2431
|
+
this._processError = (data) => {
|
|
2432
|
+
this._logger?.info(`An issue was encountered receiving updates for payload ${this._tempId} with reason: ${data.reason}. Automatic retry will occur.`);
|
|
2433
|
+
this._resetState();
|
|
2434
|
+
};
|
|
2435
|
+
this._attachHandler(eventStream, 'server-intent', this._processServerIntent);
|
|
2436
|
+
this._attachHandler(eventStream, 'put-object', this._processPutObject);
|
|
2437
|
+
this._attachHandler(eventStream, 'delete-object', this._processDeleteObject);
|
|
2438
|
+
this._attachHandler(eventStream, 'payload-transferred', this._processPayloadTransferred);
|
|
2439
|
+
this._attachHandler(eventStream, 'goodbye', this._processGoodbye);
|
|
2440
|
+
this._attachHandler(eventStream, 'error', this._processError);
|
|
2441
|
+
}
|
|
2442
|
+
addPayloadListener(listener) {
|
|
2443
|
+
this._listeners.push(listener);
|
|
2444
|
+
}
|
|
2445
|
+
removePayloadListener(listener) {
|
|
2446
|
+
const index = this._listeners.indexOf(listener, 0);
|
|
2447
|
+
if (index > -1) {
|
|
2448
|
+
this._listeners.splice(index, 1);
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
_attachHandler(stream, eventName, processor) {
|
|
2452
|
+
stream.addEventListener(eventName, async (event) => {
|
|
2453
|
+
if (event?.data) {
|
|
2454
|
+
this._logger?.debug(`Received ${eventName} event. Data is ${event.data}`);
|
|
2455
|
+
try {
|
|
2456
|
+
processor(JSON.parse(event.data));
|
|
2397
2457
|
}
|
|
2398
|
-
|
|
2399
|
-
this.
|
|
2458
|
+
catch {
|
|
2459
|
+
this._logger?.error(`Stream received data that was unable to be processed in "${eventName}" message`);
|
|
2460
|
+
this._logger?.debug(`Data follows: ${event.data}`);
|
|
2461
|
+
this._errorHandler?.(DataSourceErrorKind.InvalidData, 'Malformed data in event stream');
|
|
2400
2462
|
}
|
|
2401
|
-
}
|
|
2463
|
+
}
|
|
2464
|
+
else {
|
|
2465
|
+
this._errorHandler?.(DataSourceErrorKind.Unknown, 'Unexpected message from event stream');
|
|
2466
|
+
}
|
|
2402
2467
|
});
|
|
2403
2468
|
}
|
|
2404
|
-
|
|
2405
|
-
this.
|
|
2406
|
-
this._eventSource = undefined;
|
|
2469
|
+
_processObj(kind, jsonObj) {
|
|
2470
|
+
return this._objProcessors[kind]?.(jsonObj);
|
|
2407
2471
|
}
|
|
2408
|
-
|
|
2409
|
-
this.
|
|
2472
|
+
_resetState() {
|
|
2473
|
+
this._tempId = undefined;
|
|
2474
|
+
this._tempBasis = undefined;
|
|
2475
|
+
this._tempUpdates = [];
|
|
2410
2476
|
}
|
|
2411
2477
|
}
|
|
2412
2478
|
|
|
@@ -2421,7 +2487,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2421
2487
|
InputEvalEvent: InputEvalEvent,
|
|
2422
2488
|
InputIdentifyEvent: InputIdentifyEvent,
|
|
2423
2489
|
NullEventProcessor: NullEventProcessor,
|
|
2424
|
-
|
|
2490
|
+
PayloadReader: PayloadReader,
|
|
2425
2491
|
isLegacyUser: isLegacyUser,
|
|
2426
2492
|
isMultiKind: isMultiKind,
|
|
2427
2493
|
isSingleKind: isSingleKind,
|