@unrevealed/node
Advanced tools
Comparing version 0.0.5 to 0.0.6-rc.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnrevealedClient = exports.ReadyState = void 0; | ||
exports.UnrevealedClient = void 0; | ||
var UnrevealedClient_1 = require("./UnrevealedClient"); | ||
Object.defineProperty(exports, "ReadyState", { enumerable: true, get: function () { return UnrevealedClient_1.ReadyState; } }); | ||
Object.defineProperty(exports, "UnrevealedClient", { enumerable: true, get: function () { return UnrevealedClient_1.UnrevealedClient; } }); |
@@ -1,3 +0,4 @@ | ||
export { UnrevealedLogger } from './Logger'; | ||
export { ReadyState, UnrevealedClient, UnrevealedClientOptions, } from './UnrevealedClient'; | ||
export type { UnrevealedLogger } from './Logger'; | ||
export type { UnrevealedFeatureKey, UnrevealedFeatures, UnrevealedTeamTraits, UnrevealedUserTraits, } from './types'; | ||
export { UnrevealedClient, type ReadyState, type UnrevealedClientOptions, } from './UnrevealedClient'; | ||
//# sourceMappingURL=index.d.ts.map |
import { UnrevealedLogger } from './Logger'; | ||
export declare enum ReadyState { | ||
UNINITIALIZED = 0, | ||
CONNECTING = 1, | ||
READY = 2, | ||
CLOSED = 3 | ||
} | ||
import { Team, UnrevealedFeatureKey, User } from './types'; | ||
export type ReadyState = 'UNINITIALIZED' | 'CONNECTING' | 'READY' | 'CLOSED'; | ||
export interface UnrevealedClientOptions { | ||
@@ -13,11 +9,3 @@ apiKey: string; | ||
} | ||
interface User { | ||
id: string; | ||
traits?: Record<string, unknown>; | ||
} | ||
interface Team { | ||
id: string; | ||
traits?: Record<string, unknown>; | ||
} | ||
export declare class UnrevealedClient<TFeatureKey extends string = string> { | ||
export declare class UnrevealedClient { | ||
private _eventSource; | ||
@@ -36,3 +24,3 @@ private _featureAccesses; | ||
close(): void; | ||
isFeatureEnabled(featureKey: TFeatureKey, { user, team }?: { | ||
isFeatureEnabled(featureKey: UnrevealedFeatureKey, { user, team }?: { | ||
user?: User; | ||
@@ -44,3 +32,3 @@ team?: Team; | ||
team?: Team; | ||
}): Promise<TFeatureKey[]>; | ||
}): Promise<UnrevealedFeatureKey[]>; | ||
identify({ user, team }: { | ||
@@ -64,3 +52,2 @@ user?: User; | ||
} | ||
export {}; | ||
//# sourceMappingURL=UnrevealedClient.d.ts.map |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UnrevealedClient = exports.ReadyState = void 0; | ||
exports.UnrevealedClient = void 0; | ||
const eventsource_1 = __importDefault(require("eventsource")); | ||
@@ -22,9 +22,2 @@ const errors_1 = require("./errors"); | ||
const TRACKING_API_URL = 'https://track.unrevealed.tech'; | ||
var ReadyState; | ||
(function (ReadyState) { | ||
ReadyState[ReadyState["UNINITIALIZED"] = 0] = "UNINITIALIZED"; | ||
ReadyState[ReadyState["CONNECTING"] = 1] = "CONNECTING"; | ||
ReadyState[ReadyState["READY"] = 2] = "READY"; | ||
ReadyState[ReadyState["CLOSED"] = 3] = "CLOSED"; | ||
})(ReadyState = exports.ReadyState || (exports.ReadyState = {})); | ||
const RETRY_INTERVAL_MS = 2000; | ||
@@ -35,3 +28,3 @@ class UnrevealedClient { | ||
this._featureAccesses = new Map(); | ||
this._readyState = ReadyState.UNINITIALIZED; | ||
this._readyState = 'UNINITIALIZED'; | ||
this._connectionPromise = null; | ||
@@ -56,4 +49,3 @@ const { apiKey, apiUrl, trackingUrl, logger, defaults } = options; | ||
} | ||
const isConnectableState = this._readyState === ReadyState.UNINITIALIZED || | ||
this._readyState === ReadyState.CLOSED; | ||
const isConnectableState = this._readyState === 'UNINITIALIZED' || this._readyState === 'CLOSED'; | ||
if (isConnectableState) { | ||
@@ -68,3 +60,3 @@ this._connectionPromise = this._connectRecursive(); | ||
this._closeExistingEventSource(); | ||
this._readyState = ReadyState.CLOSED; | ||
this._readyState = 'CLOSED'; | ||
this._featureAccesses = new Map(); | ||
@@ -122,10 +114,10 @@ } | ||
_isReady() { | ||
return this._readyState === ReadyState.READY; | ||
return this._readyState === 'READY'; | ||
} | ||
_connectRecursive(attempt = 1) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this._readyState = ReadyState.CONNECTING; | ||
this._readyState = 'CONNECTING'; | ||
try { | ||
yield this._connect(); | ||
this._readyState = ReadyState.READY; | ||
this._readyState = 'READY'; | ||
this._log('Connection established'); | ||
@@ -156,3 +148,3 @@ } | ||
eventSource.addEventListener('error', (event) => { | ||
if (this._readyState === ReadyState.CONNECTING) { | ||
if (this._readyState === 'CONNECTING') { | ||
if ('status' in event && event.status === 401) { | ||
@@ -221,3 +213,3 @@ reject(new errors_1.UnauthorizedException()); | ||
_handleError(_event) { | ||
if (this._readyState === ReadyState.READY) { | ||
if (this._readyState === 'READY') { | ||
this._connectRecursive(); | ||
@@ -228,3 +220,3 @@ return; | ||
_handlePut(event) { | ||
if (this._readyState !== ReadyState.CONNECTING) { | ||
if (this._readyState !== 'CONNECTING') { | ||
return; | ||
@@ -245,3 +237,3 @@ } | ||
_handlePatch(event) { | ||
if (this._readyState !== ReadyState.READY) { | ||
if (this._readyState !== 'READY') { | ||
return; | ||
@@ -248,0 +240,0 @@ } |
{ | ||
"name": "@unrevealed/node", | ||
"version": "0.0.5", | ||
"version": "0.0.6-rc.1", | ||
"description": "Unrevealed SDK for Node", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17223
16
352