@unrevealed/node
Advanced tools
Comparing version 0.3.1-rc.3 to 0.3.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FeatureAccessUpdate = void 0; | ||
class ListUpdates { | ||
} | ||
class FeatureAccessUpdate { | ||
} | ||
exports.FeatureAccessUpdate = FeatureAccessUpdate; |
@@ -23,2 +23,15 @@ export interface UserTraits { | ||
} | ||
declare class ListUpdates { | ||
add?: string[]; | ||
remove?: string[]; | ||
} | ||
export declare class FeatureAccessUpdate { | ||
fullAccess?: boolean; | ||
users?: ListUpdates; | ||
teams?: ListUpdates; | ||
collections?: ListUpdates; | ||
userPercentage?: number; | ||
teamPercentage?: number; | ||
} | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
import { UnrevealedLogger } from './Logger'; | ||
import { FeatureAccess, FeatureKey, Team, User } from './types'; | ||
import { FeatureAccess, FeatureAccessUpdate, FeatureKey, Team, User } from './types'; | ||
export type ReadyState = 'UNINITIALIZED' | 'CONNECTING' | 'READY' | 'CLOSED'; | ||
@@ -36,2 +36,3 @@ export interface UnrevealedClientOptions { | ||
}): Promise<void>; | ||
updateFeatureAccess(featureKey: FeatureKey, access: FeatureAccessUpdate): Promise<FeatureAccess>; | ||
private _normalizeKey; | ||
@@ -38,0 +39,0 @@ private _track; |
@@ -18,6 +18,6 @@ "use strict"; | ||
const eventsource_1 = __importDefault(require("eventsource")); | ||
const Logger_1 = require("./Logger"); | ||
const constants_1 = require("./constants"); | ||
const errors_1 = require("./errors"); | ||
const fetch_1 = require("./fetch"); | ||
const Logger_1 = require("./Logger"); | ||
const SSE_API_URL = 'https://sse.unrevealed.tech'; | ||
@@ -128,2 +128,27 @@ const TRACKING_API_URL = 'https://track.unrevealed.tech'; | ||
} | ||
updateFeatureAccess(featureKey, access) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fetch = (0, fetch_1.getFetch)(); | ||
try { | ||
const response = yield fetch(`${this._apiUrl}/api/update-feature-access`, { | ||
method: 'post', | ||
headers: { | ||
Authorization: `Bearer ${this._apiKey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ key: featureKey, access }), | ||
}); | ||
const featureAccess = yield response.json(); | ||
this._featureAccesses.set(featureKey, featureAccess); | ||
return featureAccess; | ||
} | ||
catch (err) { | ||
let message = 'Error updating feature access'; | ||
if (err instanceof Error) { | ||
message = `${message}: ${err.message}`; | ||
} | ||
throw new Error(message); | ||
} | ||
}); | ||
} | ||
_normalizeKey(key) { | ||
@@ -211,3 +236,2 @@ const hash = crypto_1.default.createHash('sha1'); | ||
this._logError(errorMessage); | ||
console.log(JSON.stringify({ event })); | ||
this._handleError(event); | ||
@@ -214,0 +238,0 @@ } |
{ | ||
"name": "@unrevealed/node", | ||
"version": "0.3.1-rc.3", | ||
"version": "0.3.2", | ||
"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
26991
470
2