@launchdarkly/js-sdk-common
Advanced tools
Comparing version 2.1.0 to 2.2.0-alpha
@@ -0,1 +1,2 @@ | ||
import type { HttpErrorResponse } from './Requests'; | ||
export type EventName = 'delete' | 'patch' | 'ping' | 'put'; | ||
@@ -11,3 +12,3 @@ export type EventListener = (event?: { | ||
onclose: (() => void) | undefined; | ||
onerror: (() => void) | undefined; | ||
onerror: ((err?: HttpErrorResponse) => void) | undefined; | ||
onopen: (() => void) | undefined; | ||
@@ -21,6 +22,3 @@ onretrying: ((e: { | ||
export interface EventSourceInitDict { | ||
errorFilter: (err: { | ||
status: number; | ||
message: string; | ||
}) => boolean; | ||
errorFilter: (err: HttpErrorResponse) => boolean; | ||
headers: { | ||
@@ -27,0 +25,0 @@ [key: string]: string | string[]; |
@@ -8,2 +8,3 @@ export * from './Encoding'; | ||
export * from './EventSource'; | ||
export * from './Storage'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -24,2 +24,3 @@ "use strict"; | ||
__exportStar(require("./EventSource"), exports); | ||
__exportStar(require("./Storage"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,3 @@ import { Crypto } from './Crypto'; | ||
import { Requests } from './Requests'; | ||
import { Storage } from './Storage'; | ||
export interface Platform { | ||
@@ -30,3 +31,8 @@ /** | ||
requests: Requests; | ||
/** | ||
* The interface for session specific storage object. If the platform does not | ||
* support local storage access, this may be undefined. | ||
*/ | ||
storage?: Storage; | ||
} | ||
//# sourceMappingURL=Platform.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { EventSource, EventSourceInitDict } from './EventSource'; | ||
import type { EventSource, EventSourceInitDict } from './EventSource'; | ||
/** | ||
@@ -75,2 +75,6 @@ * Interface for headers that are part of a fetch response. | ||
} | ||
export interface HttpErrorResponse { | ||
message: string; | ||
status?: number; | ||
} | ||
//# sourceMappingURL=Requests.d.ts.map |
@@ -20,2 +20,12 @@ import { EventName, ProcessStreamResponse } from '../../api'; | ||
private logConnectionResult; | ||
/** | ||
* This is a wrapper around the passed errorHandler which adds additional | ||
* diagnostics and logging logic. | ||
* | ||
* @param err The error to be logged and handled. | ||
* @return boolean whether to retry the connection. | ||
* | ||
* @private | ||
*/ | ||
private retryAndHandleError; | ||
start(): void; | ||
@@ -22,0 +32,0 @@ stop(): void; |
@@ -5,4 +5,2 @@ "use strict"; | ||
const utils_1 = require("../../utils"); | ||
const STREAM_READ_TIMEOUT_MS = 5 * 60 * 1000; | ||
const RETRY_RESET_INTERVAL_MS = 60 * 1000; | ||
const reportJsonError = (type, data, logger, errorHandler) => { | ||
@@ -36,24 +34,33 @@ logger === null || logger === void 0 ? void 0 : logger.error(`Stream received invalid data in "${type}" message`); | ||
} | ||
/** | ||
* This is a wrapper around the passed errorHandler which adds additional | ||
* diagnostics and logging logic. | ||
* | ||
* @param err The error to be logged and handled. | ||
* @return boolean whether to retry the connection. | ||
* | ||
* @private | ||
*/ | ||
retryAndHandleError(err) { | ||
var _a, _b, _c; | ||
if (!(0, utils_1.shouldRetry)(err)) { | ||
this.logConnectionResult(false); | ||
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, new errors_1.LDStreamingError(err.message, err.status)); | ||
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error((0, utils_1.httpErrorMessage)(err, 'streaming request')); | ||
return false; | ||
} | ||
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn((0, utils_1.httpErrorMessage)(err, 'streaming request', 'will retry')); | ||
this.logConnectionResult(false); | ||
this.logConnectionStarted(); | ||
return true; | ||
} | ||
start() { | ||
this.logConnectionStarted(); | ||
const errorFilter = (err) => { | ||
var _a, _b, _c; | ||
if (err.status && !(0, errors_1.isHttpRecoverable)(err.status)) { | ||
this.logConnectionResult(false); | ||
(_a = this.errorHandler) === null || _a === void 0 ? void 0 : _a.call(this, new errors_1.LDStreamingError(err.message, err.status)); | ||
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error((0, utils_1.httpErrorMessage)(err, 'streaming request')); | ||
return false; | ||
} | ||
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn((0, utils_1.httpErrorMessage)(err, 'streaming request', 'will retry')); | ||
this.logConnectionResult(false); | ||
this.logConnectionStarted(); | ||
return true; | ||
}; | ||
// TLS is handled by the platform implementation. | ||
const eventSource = this.requests.createEventSource(this.streamUri, { | ||
headers: this.headers, | ||
errorFilter, | ||
errorFilter: (error) => this.retryAndHandleError(error), | ||
initialRetryDelayMillis: 1000 * this.streamInitialReconnectDelay, | ||
readTimeoutMillis: STREAM_READ_TIMEOUT_MS, | ||
retryResetIntervalMillis: RETRY_RESET_INTERVAL_MS, | ||
readTimeoutMillis: 5 * 60 * 1000, | ||
retryResetIntervalMillis: 60 * 1000, | ||
}); | ||
@@ -60,0 +67,0 @@ this.eventSource = eventSource; |
@@ -1,2 +0,2 @@ | ||
export default function clone(obj: any): any; | ||
export default function clone<T>(obj: any): T; | ||
//# sourceMappingURL=clone.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { Info } from '../api'; | ||
import { Encoding, HttpErrorResponse, Info } from '../api'; | ||
import { ApplicationTags } from '../options'; | ||
@@ -10,6 +10,14 @@ export type LDHeaders = { | ||
export declare function defaultHeaders(sdkKey: string, info: Info, tags?: ApplicationTags, includeAuthorizationHeader?: boolean): LDHeaders; | ||
export declare function httpErrorMessage(err: { | ||
status: number; | ||
message: string; | ||
}, context: string, retryMessage?: string): string; | ||
export declare function httpErrorMessage(err: HttpErrorResponse, context: string, retryMessage?: string): string; | ||
export declare function shouldRetry({ status }: HttpErrorResponse): boolean; | ||
/** | ||
* In react-native use base64-js to polyfill btoa. This is safe | ||
* because the react-native repo uses it too. Set the global.btoa to the encode | ||
* function of base64-js. | ||
* https://github.com/beatgammit/base64-js | ||
* https://github.com/axios/axios/issues/2235#issuecomment-512204616 | ||
* | ||
* Ripped from https://thewoods.blog/base64url/ | ||
*/ | ||
export declare const base64UrlEncode: (s: string, encoding: Encoding) => string; | ||
//# sourceMappingURL=http.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.httpErrorMessage = exports.defaultHeaders = void 0; | ||
exports.base64UrlEncode = exports.shouldRetry = exports.httpErrorMessage = exports.defaultHeaders = void 0; | ||
const errors_1 = require("../errors"); | ||
function defaultHeaders(sdkKey, info, tags, includeAuthorizationHeader = true) { | ||
@@ -37,2 +38,17 @@ const { userAgentBase, version, wrapperName, wrapperVersion } = info.sdkData(); | ||
exports.httpErrorMessage = httpErrorMessage; | ||
function shouldRetry({ status }) { | ||
return status ? (0, errors_1.isHttpRecoverable)(status) : true; | ||
} | ||
exports.shouldRetry = shouldRetry; | ||
/** | ||
* In react-native use base64-js to polyfill btoa. This is safe | ||
* because the react-native repo uses it too. Set the global.btoa to the encode | ||
* function of base64-js. | ||
* https://github.com/beatgammit/base64-js | ||
* https://github.com/axios/axios/issues/2235#issuecomment-512204616 | ||
* | ||
* Ripped from https://thewoods.blog/base64url/ | ||
*/ | ||
const base64UrlEncode = (s, encoding) => encoding.btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | ||
exports.base64UrlEncode = base64UrlEncode; | ||
//# sourceMappingURL=http.js.map |
import clone from './clone'; | ||
import { secondsToMillis } from './date'; | ||
import { defaultHeaders, httpErrorMessage, LDHeaders } from './http'; | ||
import fastDeepEqual from './fast-deep-equal'; | ||
import { base64UrlEncode, defaultHeaders, httpErrorMessage, LDHeaders, shouldRetry } from './http'; | ||
import noop from './noop'; | ||
import sleep from './sleep'; | ||
import { VoidFunction } from './VoidFunction'; | ||
export { clone, defaultHeaders, httpErrorMessage, noop, LDHeaders, secondsToMillis, sleep, VoidFunction, }; | ||
export { base64UrlEncode, clone, defaultHeaders, fastDeepEqual, httpErrorMessage, noop, LDHeaders, shouldRetry, secondsToMillis, sleep, VoidFunction, }; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sleep = exports.secondsToMillis = exports.noop = exports.httpErrorMessage = exports.defaultHeaders = exports.clone = void 0; | ||
exports.sleep = exports.secondsToMillis = exports.shouldRetry = exports.noop = exports.httpErrorMessage = exports.fastDeepEqual = exports.defaultHeaders = exports.clone = exports.base64UrlEncode = void 0; | ||
const clone_1 = require("./clone"); | ||
@@ -8,5 +8,9 @@ exports.clone = clone_1.default; | ||
Object.defineProperty(exports, "secondsToMillis", { enumerable: true, get: function () { return date_1.secondsToMillis; } }); | ||
const fast_deep_equal_1 = require("./fast-deep-equal"); | ||
exports.fastDeepEqual = fast_deep_equal_1.default; | ||
const http_1 = require("./http"); | ||
Object.defineProperty(exports, "base64UrlEncode", { enumerable: true, get: function () { return http_1.base64UrlEncode; } }); | ||
Object.defineProperty(exports, "defaultHeaders", { enumerable: true, get: function () { return http_1.defaultHeaders; } }); | ||
Object.defineProperty(exports, "httpErrorMessage", { enumerable: true, get: function () { return http_1.httpErrorMessage; } }); | ||
Object.defineProperty(exports, "shouldRetry", { enumerable: true, get: function () { return http_1.shouldRetry; } }); | ||
const noop_1 = require("./noop"); | ||
@@ -13,0 +17,0 @@ exports.noop = noop_1.default; |
{ | ||
"name": "@launchdarkly/js-sdk-common", | ||
"version": "2.1.0", | ||
"version": "2.2.0-alpha", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
286708
344
4268
1