@launchdarkly/js-client-sdk-common 1.6.0 → 1.8.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 +41 -0
- package/README.md +1 -1
- package/dist/DataManager.d.ts +49 -0
- package/dist/DataManager.d.ts.map +1 -0
- package/dist/DataManager.js +98 -0
- package/dist/DataManager.js.map +1 -0
- package/dist/LDClientImpl.d.ts +9 -44
- package/dist/LDClientImpl.d.ts.map +1 -1
- package/dist/LDClientImpl.js +18 -144
- package/dist/LDClientImpl.js.map +1 -1
- package/dist/api/LDClient.d.ts +0 -14
- package/dist/api/LDClient.d.ts.map +1 -1
- package/dist/api/LDOptions.d.ts +22 -10
- package/dist/api/LDOptions.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/configuration/Configuration.d.ts +57 -16
- package/dist/configuration/Configuration.d.ts.map +1 -1
- package/dist/configuration/Configuration.js +14 -8
- package/dist/configuration/Configuration.js.map +1 -1
- package/dist/configuration/index.d.ts +2 -2
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +4 -1
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/validators.d.ts.map +1 -1
- package/dist/configuration/validators.js +2 -9
- package/dist/configuration/validators.js.map +1 -1
- package/dist/context/addAutoEnv.d.ts +2 -2
- package/dist/context/addAutoEnv.d.ts.map +1 -1
- package/dist/context/addAutoEnv.js +5 -6
- package/dist/context/addAutoEnv.js.map +1 -1
- package/dist/context/ensureKey.js +1 -1
- package/dist/context/ensureKey.js.map +1 -1
- package/dist/crypto/digest.d.ts +3 -0
- package/dist/crypto/digest.d.ts.map +1 -0
- package/dist/crypto/digest.js +14 -0
- package/dist/crypto/digest.js.map +1 -0
- package/dist/diagnostics/createDiagnosticsInitConfig.d.ts +1 -1
- package/dist/diagnostics/createDiagnosticsInitConfig.d.ts.map +1 -1
- package/dist/diagnostics/createDiagnosticsInitConfig.js +2 -2
- package/dist/diagnostics/createDiagnosticsInitConfig.js.map +1 -1
- package/dist/diagnostics/createDiagnosticsManager.d.ts +1 -1
- package/dist/diagnostics/createDiagnosticsManager.d.ts.map +1 -1
- package/dist/events/createEventProcessor.d.ts +3 -3
- package/dist/events/createEventProcessor.d.ts.map +1 -1
- package/dist/events/createEventProcessor.js +2 -2
- package/dist/events/createEventProcessor.js.map +1 -1
- package/dist/flag-manager/FlagManager.d.ts +29 -15
- package/dist/flag-manager/FlagManager.d.ts.map +1 -1
- package/dist/flag-manager/FlagManager.js +10 -36
- package/dist/flag-manager/FlagManager.js.map +1 -1
- package/dist/flag-manager/FlagPersistence.d.ts +2 -1
- package/dist/flag-manager/FlagPersistence.d.ts.map +1 -1
- package/dist/flag-manager/FlagPersistence.js +5 -5
- package/dist/flag-manager/FlagPersistence.js.map +1 -1
- package/dist/flag-manager/FlagStore.d.ts.map +1 -1
- package/dist/flag-manager/FlagStore.js +4 -1
- package/dist/flag-manager/FlagStore.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/polling/PollingProcessor.d.ts.map +1 -1
- package/dist/polling/PollingProcessor.js +22 -5
- package/dist/polling/PollingProcessor.js.map +1 -1
- package/dist/polling/Requestor.d.ts +16 -1
- package/dist/polling/Requestor.d.ts.map +1 -1
- package/dist/polling/Requestor.js +6 -8
- package/dist/polling/Requestor.js.map +1 -1
- package/dist/storage/namespaceUtils.d.ts +7 -7
- package/dist/storage/namespaceUtils.d.ts.map +1 -1
- package/dist/storage/namespaceUtils.js +10 -9
- package/dist/storage/namespaceUtils.js.map +1 -1
- package/dist/streaming/DataSourceConfig.d.ts +20 -0
- package/dist/streaming/DataSourceConfig.d.ts.map +1 -0
- package/dist/streaming/DataSourceConfig.js +3 -0
- package/dist/streaming/DataSourceConfig.js.map +1 -0
- package/dist/streaming/StreamingProcessor.d.ts +33 -0
- package/dist/streaming/StreamingProcessor.d.ts.map +1 -0
- package/dist/streaming/StreamingProcessor.js +126 -0
- package/dist/streaming/StreamingProcessor.js.map +1 -0
- package/dist/streaming/index.d.ts +4 -0
- package/dist/streaming/index.d.ts.map +1 -0
- package/dist/streaming/index.js +6 -0
- package/dist/streaming/index.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.namespaceForContextData = exports.namespaceForContextIndex = exports.namespaceForGeneratedContextKey = exports.namespaceForAnonymousGeneratedContextKey = exports.namespaceForEnvironment = exports.concatNamespacesAndValues = void 0;
|
|
4
|
+
const digest_1 = require("../crypto/digest");
|
|
4
5
|
/**
|
|
5
6
|
* Hashes the input and encodes it as base64
|
|
6
7
|
*/
|
|
7
8
|
function hashAndBase64Encode(crypto) {
|
|
8
|
-
return (input) => crypto.createHash('sha256').update(input)
|
|
9
|
+
return async (input) => (0, digest_1.default)(crypto.createHash('sha256').update(input), 'base64');
|
|
9
10
|
}
|
|
10
|
-
const noop = (input) => input; // no-op transform
|
|
11
|
-
function concatNamespacesAndValues(parts) {
|
|
12
|
-
const processedParts = parts.map((part) => part.transform(part.value)); // use the transform from each part to transform the value
|
|
11
|
+
const noop = async (input) => input; // no-op transform
|
|
12
|
+
async function concatNamespacesAndValues(parts) {
|
|
13
|
+
const processedParts = await Promise.all(parts.map((part) => part.transform(part.value))); // use the transform from each part to transform the value
|
|
13
14
|
return processedParts.join('_');
|
|
14
15
|
}
|
|
15
16
|
exports.concatNamespacesAndValues = concatNamespacesAndValues;
|
|
16
|
-
function namespaceForEnvironment(crypto, sdkKey) {
|
|
17
|
+
async function namespaceForEnvironment(crypto, sdkKey) {
|
|
17
18
|
return concatNamespacesAndValues([
|
|
18
19
|
{ value: 'LaunchDarkly', transform: noop },
|
|
19
20
|
{ value: sdkKey, transform: hashAndBase64Encode(crypto) }, // hash sdk key and encode it
|
|
@@ -28,7 +29,7 @@ exports.namespaceForEnvironment = namespaceForEnvironment;
|
|
|
28
29
|
* when the data under the LaunchDarkly_AnonymousKeys namespace is merged with data under the
|
|
29
30
|
* LaunchDarkly_ContextKeys namespace.
|
|
30
31
|
*/
|
|
31
|
-
function namespaceForAnonymousGeneratedContextKey(kind) {
|
|
32
|
+
async function namespaceForAnonymousGeneratedContextKey(kind) {
|
|
32
33
|
return concatNamespacesAndValues([
|
|
33
34
|
{ value: 'LaunchDarkly', transform: noop },
|
|
34
35
|
{ value: 'AnonymousKeys', transform: noop },
|
|
@@ -36,7 +37,7 @@ function namespaceForAnonymousGeneratedContextKey(kind) {
|
|
|
36
37
|
]);
|
|
37
38
|
}
|
|
38
39
|
exports.namespaceForAnonymousGeneratedContextKey = namespaceForAnonymousGeneratedContextKey;
|
|
39
|
-
function namespaceForGeneratedContextKey(kind) {
|
|
40
|
+
async function namespaceForGeneratedContextKey(kind) {
|
|
40
41
|
return concatNamespacesAndValues([
|
|
41
42
|
{ value: 'LaunchDarkly', transform: noop },
|
|
42
43
|
{ value: 'ContextKeys', transform: noop },
|
|
@@ -44,14 +45,14 @@ function namespaceForGeneratedContextKey(kind) {
|
|
|
44
45
|
]);
|
|
45
46
|
}
|
|
46
47
|
exports.namespaceForGeneratedContextKey = namespaceForGeneratedContextKey;
|
|
47
|
-
function namespaceForContextIndex(environmentNamespace) {
|
|
48
|
+
async function namespaceForContextIndex(environmentNamespace) {
|
|
48
49
|
return concatNamespacesAndValues([
|
|
49
50
|
{ value: environmentNamespace, transform: noop },
|
|
50
51
|
{ value: 'ContextIndex', transform: noop },
|
|
51
52
|
]);
|
|
52
53
|
}
|
|
53
54
|
exports.namespaceForContextIndex = namespaceForContextIndex;
|
|
54
|
-
function namespaceForContextData(crypto, environmentNamespace, context) {
|
|
55
|
+
async function namespaceForContextData(crypto, environmentNamespace, context) {
|
|
55
56
|
return concatNamespacesAndValues([
|
|
56
57
|
{ value: environmentNamespace, transform: noop },
|
|
57
58
|
{ value: context.canonicalKey, transform: hashAndBase64Encode(crypto) }, // hash and encode canonical key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespaceUtils.js","sourceRoot":"","sources":["../../src/storage/namespaceUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"namespaceUtils.js","sourceRoot":"","sources":["../../src/storage/namespaceUtils.ts"],"names":[],"mappings":";;;AAEA,6CAAsC;AAItC;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAA,gBAAM,EAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,IAAI,GAAG,KAAK,EAAE,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,kBAAkB;AAExD,KAAK,UAAU,yBAAyB,CAC7C,KAAqF;IAErF,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,0DAA0D;IACrJ,OAAO,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AALD,8DAKC;AAEM,KAAK,UAAU,uBAAuB,CAAC,MAAc,EAAE,MAAc;IAC1E,OAAO,yBAAyB,CAAC;QAC/B,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE;QAC1C,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,CAAC,MAAM,CAAC,EAAE,EAAE,6BAA6B;KACzF,CAAC,CAAC;AACL,CAAC;AALD,0DAKC;AAED;;;;;;;GAOG;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dk-common';
|
|
2
|
+
export interface DataSourceConfig {
|
|
3
|
+
credential: string;
|
|
4
|
+
serviceEndpoints: ServiceEndpoints;
|
|
5
|
+
baseHeaders: LDHeaders;
|
|
6
|
+
withReasons: boolean;
|
|
7
|
+
useReport: boolean;
|
|
8
|
+
paths: DataSourcePaths;
|
|
9
|
+
}
|
|
10
|
+
export interface PollingDataSourceConfig extends DataSourceConfig {
|
|
11
|
+
pollInterval: number;
|
|
12
|
+
}
|
|
13
|
+
export interface StreamingDataSourceConfig extends DataSourceConfig {
|
|
14
|
+
initialRetryDelayMillis: number;
|
|
15
|
+
}
|
|
16
|
+
export interface DataSourcePaths {
|
|
17
|
+
pathGet(encoding: Encoding, plainContextString: string): string;
|
|
18
|
+
pathReport(encoding: Encoding, plainContextString: string): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=DataSourceConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataSourceConfig.d.ts","sourceRoot":"","sources":["../../src/streaming/DataSourceConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpF,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,SAAS,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,eAAe,CAAC;CACxB;AAED,MAAM,WAAW,uBAAwB,SAAQ,gBAAgB;IAC/D,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IACjE,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAAC;IAChE,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAAC;CACpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataSourceConfig.js","sourceRoot":"","sources":["../../src/streaming/DataSourceConfig.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Encoding, EventName, internal, LDLogger, ProcessStreamResponse, Requests, subsystem } from '@launchdarkly/js-sdk-common';
|
|
2
|
+
import { StreamingDataSourceConfig } from './DataSourceConfig';
|
|
3
|
+
declare class StreamingProcessor implements subsystem.LDStreamProcessor {
|
|
4
|
+
private readonly plainContextString;
|
|
5
|
+
private readonly dataSourceConfig;
|
|
6
|
+
private readonly listeners;
|
|
7
|
+
private readonly requests;
|
|
8
|
+
private readonly diagnosticsManager?;
|
|
9
|
+
private readonly errorHandler?;
|
|
10
|
+
private readonly logger?;
|
|
11
|
+
private readonly headers;
|
|
12
|
+
private readonly streamUri;
|
|
13
|
+
private eventSource?;
|
|
14
|
+
private connectionAttemptStartTime?;
|
|
15
|
+
constructor(plainContextString: string, dataSourceConfig: StreamingDataSourceConfig, listeners: Map<EventName, ProcessStreamResponse>, requests: Requests, encoding: Encoding, diagnosticsManager?: internal.DiagnosticsManager | undefined, errorHandler?: internal.StreamingErrorHandler | undefined, logger?: LDLogger | undefined);
|
|
16
|
+
private logConnectionStarted;
|
|
17
|
+
private logConnectionResult;
|
|
18
|
+
/**
|
|
19
|
+
* This is a wrapper around the passed errorHandler which adds additional
|
|
20
|
+
* diagnostics and logging logic.
|
|
21
|
+
*
|
|
22
|
+
* @param err The error to be logged and handled.
|
|
23
|
+
* @return boolean whether to retry the connection.
|
|
24
|
+
*
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private retryAndHandleError;
|
|
28
|
+
start(): void;
|
|
29
|
+
stop(): void;
|
|
30
|
+
close(): void;
|
|
31
|
+
}
|
|
32
|
+
export default StreamingProcessor;
|
|
33
|
+
//# sourceMappingURL=StreamingProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingProcessor.d.ts","sourceRoot":"","sources":["../../src/streaming/StreamingProcessor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EAKT,QAAQ,EACR,QAAQ,EAER,qBAAqB,EACrB,QAAQ,EAER,SAAS,EACV,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAa/D,cAAM,kBAAmB,YAAW,SAAS,CAAC,iBAAiB;IAQ3D,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAEzB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAd1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,0BAA0B,CAAC,CAAS;gBAGzB,kBAAkB,EAAE,MAAM,EAC1B,gBAAgB,EAAE,yBAAyB,EAC3C,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,qBAAqB,CAAC,EAChD,QAAQ,EAAE,QAAQ,EACnC,QAAQ,EAAE,QAAQ,EACD,kBAAkB,CAAC,yCAA6B,EAChD,YAAY,CAAC,4CAAgC,EAC7C,MAAM,CAAC,sBAAU;IAwBpC,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,mBAAmB;IAY3B;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;IAc3B,KAAK;IA+DL,IAAI;IAKJ,KAAK;CAGN;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const js_sdk_common_1 = require("@launchdarkly/js-sdk-common");
|
|
4
|
+
const reportJsonError = (type, data, logger, errorHandler) => {
|
|
5
|
+
logger === null || logger === void 0 ? void 0 : logger.error(`Stream received invalid data in "${type}" message`);
|
|
6
|
+
logger === null || logger === void 0 ? void 0 : logger.debug(`Invalid JSON follows: ${data}`);
|
|
7
|
+
errorHandler === null || errorHandler === void 0 ? void 0 : errorHandler(new js_sdk_common_1.LDStreamingError('Malformed JSON data in event stream'));
|
|
8
|
+
};
|
|
9
|
+
class StreamingProcessor {
|
|
10
|
+
constructor(plainContextString, dataSourceConfig, listeners, requests, encoding, diagnosticsManager, errorHandler, logger) {
|
|
11
|
+
this.plainContextString = plainContextString;
|
|
12
|
+
this.dataSourceConfig = dataSourceConfig;
|
|
13
|
+
this.listeners = listeners;
|
|
14
|
+
this.requests = requests;
|
|
15
|
+
this.diagnosticsManager = diagnosticsManager;
|
|
16
|
+
this.errorHandler = errorHandler;
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
// TODO: SC-255969 Implement better REPORT fallback logic
|
|
19
|
+
if (dataSourceConfig.useReport && !requests.getEventSourceCapabilities().customMethod) {
|
|
20
|
+
logger === null || logger === void 0 ? void 0 : logger.error("Configuration option useReport is true, but platform's EventSource does not support custom HTTP methods. Streaming may not work.");
|
|
21
|
+
}
|
|
22
|
+
const path = dataSourceConfig.useReport
|
|
23
|
+
? dataSourceConfig.paths.pathReport(encoding, plainContextString)
|
|
24
|
+
: dataSourceConfig.paths.pathGet(encoding, plainContextString);
|
|
25
|
+
const parameters = [];
|
|
26
|
+
if (this.dataSourceConfig.withReasons) {
|
|
27
|
+
parameters.push({ key: 'withReasons', value: 'true' });
|
|
28
|
+
}
|
|
29
|
+
this.requests = requests;
|
|
30
|
+
this.headers = Object.assign({}, dataSourceConfig.baseHeaders);
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.streamUri = (0, js_sdk_common_1.getStreamingUri)(dataSourceConfig.serviceEndpoints, path, parameters);
|
|
33
|
+
}
|
|
34
|
+
logConnectionStarted() {
|
|
35
|
+
this.connectionAttemptStartTime = Date.now();
|
|
36
|
+
}
|
|
37
|
+
logConnectionResult(success) {
|
|
38
|
+
if (this.connectionAttemptStartTime && this.diagnosticsManager) {
|
|
39
|
+
this.diagnosticsManager.recordStreamInit(this.connectionAttemptStartTime, !success, Date.now() - this.connectionAttemptStartTime);
|
|
40
|
+
}
|
|
41
|
+
this.connectionAttemptStartTime = undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This is a wrapper around the passed errorHandler which adds additional
|
|
45
|
+
* diagnostics and logging logic.
|
|
46
|
+
*
|
|
47
|
+
* @param err The error to be logged and handled.
|
|
48
|
+
* @return boolean whether to retry the connection.
|
|
49
|
+
*
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
retryAndHandleError(err) {
|
|
53
|
+
var _a, _b, _c;
|
|
54
|
+
if (!(0, js_sdk_common_1.shouldRetry)(err)) {
|
|
55
|
+
this.logConnectionResult(false);
|
|
56
|
+
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, new js_sdk_common_1.LDStreamingError(err.message, err.status));
|
|
57
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error((0, js_sdk_common_1.httpErrorMessage)(err, 'streaming request'));
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn((0, js_sdk_common_1.httpErrorMessage)(err, 'streaming request', 'will retry'));
|
|
61
|
+
this.logConnectionResult(false);
|
|
62
|
+
this.logConnectionStarted();
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
start() {
|
|
66
|
+
this.logConnectionStarted();
|
|
67
|
+
let methodAndBodyOverrides;
|
|
68
|
+
if (this.dataSourceConfig.useReport) {
|
|
69
|
+
// REPORT will include a body, so content type is required.
|
|
70
|
+
this.headers['content-type'] = 'application/json';
|
|
71
|
+
// orverrides default method with REPORT and adds body.
|
|
72
|
+
methodAndBodyOverrides = { method: 'REPORT', body: this.plainContextString };
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// no method or body override
|
|
76
|
+
methodAndBodyOverrides = {};
|
|
77
|
+
}
|
|
78
|
+
// TLS is handled by the platform implementation.
|
|
79
|
+
const eventSource = this.requests.createEventSource(this.streamUri, Object.assign(Object.assign({ headers: this.headers }, methodAndBodyOverrides), { errorFilter: (error) => this.retryAndHandleError(error), initialRetryDelayMillis: this.dataSourceConfig.initialRetryDelayMillis, readTimeoutMillis: 5 * 60 * 1000, retryResetIntervalMillis: 60 * 1000 }));
|
|
80
|
+
this.eventSource = eventSource;
|
|
81
|
+
eventSource.onclose = () => {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info('Closed LaunchDarkly stream connection');
|
|
84
|
+
};
|
|
85
|
+
eventSource.onerror = () => {
|
|
86
|
+
// The work is done by `errorFilter`.
|
|
87
|
+
};
|
|
88
|
+
eventSource.onopen = () => {
|
|
89
|
+
var _a;
|
|
90
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info('Opened LaunchDarkly stream connection');
|
|
91
|
+
};
|
|
92
|
+
eventSource.onretrying = (e) => {
|
|
93
|
+
var _a;
|
|
94
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`Will retry stream connection in ${e.delayMillis} milliseconds`);
|
|
95
|
+
};
|
|
96
|
+
this.listeners.forEach(({ deserializeData, processJson }, eventName) => {
|
|
97
|
+
eventSource.addEventListener(eventName, (event) => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug(`Received ${eventName} event`);
|
|
100
|
+
if (event === null || event === void 0 ? void 0 : event.data) {
|
|
101
|
+
this.logConnectionResult(true);
|
|
102
|
+
const { data } = event;
|
|
103
|
+
const dataJson = deserializeData(data);
|
|
104
|
+
if (!dataJson) {
|
|
105
|
+
reportJsonError(eventName, data, this.logger, this.errorHandler);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
processJson(dataJson);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
(_b = this.errorHandler) === null || _b === void 0 ? void 0 : _b.call(this, new js_sdk_common_1.LDStreamingError('Unexpected payload from event stream'));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
stop() {
|
|
117
|
+
var _a;
|
|
118
|
+
(_a = this.eventSource) === null || _a === void 0 ? void 0 : _a.close();
|
|
119
|
+
this.eventSource = undefined;
|
|
120
|
+
}
|
|
121
|
+
close() {
|
|
122
|
+
this.stop();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.default = StreamingProcessor;
|
|
126
|
+
//# sourceMappingURL=StreamingProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StreamingProcessor.js","sourceRoot":"","sources":["../../src/streaming/StreamingProcessor.ts"],"names":[],"mappings":";;AAAA,+DAcqC;AAIrC,MAAM,eAAe,GAAG,CACtB,IAAY,EACZ,IAAY,EACZ,MAAiB,EACjB,YAA6C,EAC7C,EAAE;IACF,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,oCAAoC,IAAI,WAAW,CAAC,CAAC;IACnE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;IAC/C,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,IAAI,gCAAgB,CAAC,qCAAqC,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,kBAAkB;IAOtB,YACmB,kBAA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ACrE,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;;gBAChD,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,CAAC,YAAY,SAAS,QAAQ,CAAC,CAAC;gBAElD,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,EAAE;oBACf,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;oBAC/B,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;oBACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;oBAEvC,IAAI,CAAC,QAAQ,EAAE;wBACb,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;wBACjE,OAAO;qBACR;oBACD,WAAW,CAAC,QAAQ,CAAC,CAAC;iBACvB;qBAAM;oBACL,MAAA,IAAI,CAAC,YAAY,qDAAG,IAAI,gCAAgB,CAAC,sCAAsC,CAAC,CAAC,CAAC;iBACnF;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI;;QACF,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;CACF;AAED,kBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DataSourcePaths, PollingDataSourceConfig, StreamingDataSourceConfig } from './DataSourceConfig';
|
|
2
|
+
import StreamingProcessor from './StreamingProcessor';
|
|
3
|
+
export { DataSourcePaths, PollingDataSourceConfig, StreamingProcessor, StreamingDataSourceConfig };
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/streaming/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,yBAAyB,EAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamingProcessor = void 0;
|
|
4
|
+
const StreamingProcessor_1 = require("./StreamingProcessor");
|
|
5
|
+
exports.StreamingProcessor = StreamingProcessor_1.default;
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/streaming/index.ts"],"names":[],"mappings":";;;AAKA,6DAAsD;AAEH,6BAF5C,4BAAkB,CAE4C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@launchdarkly/js-client-sdk-common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@launchdarkly/js-sdk-common": "2.
|
|
33
|
+
"@launchdarkly/js-sdk-common": "2.9.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@launchdarkly/private-js-mocks": "0.0.1",
|