unleash-client
Advanced tools
Comparing version 3.18.0 to 3.18.1
# Changelog | ||
# 3.18.1 | ||
fix: add testcase for config-hash | ||
chore(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#423) | ||
fix: cyclic dependencies | ||
fix: only produce hash of primitive values | ||
chore(deps): update dependency @typescript-eslint/eslint-plugin to v5.51.0 (#419) | ||
# 3.18.0 | ||
@@ -4,0 +13,0 @@ |
@@ -1,1 +0,1 @@ | ||
{ "name": "unleash-client-node", "version": "3.18.0", "sdkVersion": "unleash-client-node:3.18.0" } | ||
{ "name": "unleash-client-node", "version": "3.18.1", "sdkVersion": "unleash-client-node:3.18.1" } |
@@ -7,4 +7,4 @@ import { Context } from './context'; | ||
export declare function generateInstanceId(instanceId?: string): string; | ||
export declare function generateHashOfObject(o: Object): string; | ||
export declare function generateHashOfConfig(o: Object): string; | ||
export declare function getAppliedJitter(jitter: number): number; | ||
//# sourceMappingURL=helpers.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAppliedJitter = exports.generateHashOfObject = exports.generateInstanceId = exports.safeName = exports.resolveContextValue = exports.createFallbackFunction = void 0; | ||
exports.getAppliedJitter = exports.generateHashOfConfig = exports.generateInstanceId = exports.safeName = exports.resolveContextValue = exports.createFallbackFunction = void 0; | ||
var os_1 = require("os"); | ||
@@ -48,7 +48,7 @@ var murmurHash3 = require("murmurhash3js"); | ||
exports.generateInstanceId = generateInstanceId; | ||
function generateHashOfObject(o) { | ||
function generateHashOfConfig(o) { | ||
var oAsString = JSON.stringify(o); | ||
return murmurHash3.x86.hash128(oAsString); | ||
} | ||
exports.generateHashOfObject = generateHashOfObject; | ||
exports.generateHashOfConfig = generateHashOfConfig; | ||
function getAppliedJitter(jitter) { | ||
@@ -55,0 +55,0 @@ var appliedJitter = Math.random() * jitter; |
@@ -1,2 +0,2 @@ | ||
import { Unleash, UnleashConfig } from './unleash'; | ||
import { Unleash } from './unleash'; | ||
import { Variant } from './variant'; | ||
@@ -8,2 +8,3 @@ import { Context } from './context'; | ||
import InMemStorageProvider from './repository/storage-provider-in-mem'; | ||
import { UnleashConfig } from './unleash-config'; | ||
export { Strategy } from './strategy/index'; | ||
@@ -10,0 +11,0 @@ export { Context, Variant, Unleash, TagFilter, InMemStorageProvider, UnleashEvents }; |
@@ -8,9 +8,2 @@ export interface StorageProvider<T> { | ||
} | ||
export declare class FileStorageProvider<T> implements StorageProvider<T> { | ||
private backupPath; | ||
constructor(backupPath: string); | ||
private getPath; | ||
set(key: string, data: T): Promise<void>; | ||
get(key: string): Promise<T | undefined>; | ||
} | ||
//# sourceMappingURL=storage-provider.d.ts.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FileStorageProvider = void 0; | ||
var path_1 = require("path"); | ||
var fs_1 = require("fs"); | ||
var helpers_1 = require("../helpers"); | ||
var writeFile = fs_1.promises.writeFile, readFile = fs_1.promises.readFile; | ||
var FileStorageProvider = /** @class */ (function () { | ||
function FileStorageProvider(backupPath) { | ||
if (!backupPath) { | ||
throw new Error('backup Path is required'); | ||
} | ||
this.backupPath = backupPath; | ||
} | ||
FileStorageProvider.prototype.getPath = function (key) { | ||
return (0, path_1.join)(this.backupPath, "/unleash-backup-".concat((0, helpers_1.safeName)(key), ".json")); | ||
}; | ||
FileStorageProvider.prototype.set = function (key, data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, writeFile(this.getPath(key), JSON.stringify(data))]; | ||
}); | ||
}); | ||
}; | ||
FileStorageProvider.prototype.get = function (key) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path, data, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
path = this.getPath(key); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, readFile(path, 'utf8')]; | ||
case 2: | ||
data = _a.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
if (error_1.code !== 'ENOENT') { | ||
throw error_1; | ||
} | ||
else { | ||
return [2 /*return*/, undefined]; | ||
} | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
if (!data || data.trim().length === 0) { | ||
return [2 /*return*/, undefined]; | ||
} | ||
try { | ||
return [2 /*return*/, JSON.parse(data)]; | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
error.message = "Unleash storage failed parsing file ".concat(path, ": ").concat(error.message); | ||
} | ||
throw error; | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return FileStorageProvider; | ||
}()); | ||
exports.FileStorageProvider = FileStorageProvider; | ||
//# sourceMappingURL=storage-provider.js.map |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { RepositoryInterface } from './repository'; | ||
import { CustomHeaders, CustomHeadersFunction } from './headers'; | ||
import { Context } from './context'; | ||
import { Strategy } from './strategy'; | ||
import { ClientFeaturesResponse, FeatureInterface } from './feature'; | ||
import { FeatureInterface } from './feature'; | ||
import { Variant } from './variant'; | ||
import { FallbackFunction } from './helpers'; | ||
import { HttpOptions } from './http-options'; | ||
import { TagFilter } from './tags'; | ||
import { BootstrapOptions } from './repository/bootstrap-provider'; | ||
import { StorageProvider } from './repository/storage-provider'; | ||
import { UnleashEvents } from './events'; | ||
import { UnleashConfig } from './unleash-config'; | ||
export { Strategy, UnleashEvents }; | ||
export interface UnleashConfig { | ||
appName: string; | ||
environment?: string; | ||
instanceId?: string; | ||
url: string; | ||
refreshInterval?: number; | ||
projectName?: string; | ||
metricsInterval?: number; | ||
metricsJitter?: number; | ||
namePrefix?: string; | ||
disableMetrics?: boolean; | ||
backupPath?: string; | ||
strategies?: Strategy[]; | ||
customHeaders?: CustomHeaders; | ||
customHeadersFunction?: CustomHeadersFunction; | ||
timeout?: number; | ||
repository?: RepositoryInterface; | ||
httpOptions?: HttpOptions; | ||
tags?: Array<TagFilter>; | ||
bootstrap?: BootstrapOptions; | ||
bootstrapOverride?: boolean; | ||
storageProvider?: StorageProvider<ClientFeaturesResponse>; | ||
disableAutoStart?: boolean; | ||
skipInstanceCountWarning?: boolean; | ||
} | ||
export interface StaticContext { | ||
@@ -42,0 +12,0 @@ appName: string; |
@@ -76,5 +76,5 @@ "use strict"; | ||
var bootstrap_provider_1 = require("./repository/bootstrap-provider"); | ||
var storage_provider_1 = require("./repository/storage-provider"); | ||
var events_2 = require("./events"); | ||
Object.defineProperty(exports, "UnleashEvents", { enumerable: true, get: function () { return events_2.UnleashEvents; } }); | ||
var storage_provider_file_1 = require("./repository/storage-provider-file"); | ||
var BACKUP_PATH = (0, os_1.tmpdir)(); | ||
@@ -127,3 +127,3 @@ var Unleash = /** @class */ (function (_super) { | ||
bootstrapOverride: bootstrapOverride, | ||
storageProvider: storageProvider || new storage_provider_1.FileStorageProvider(backupPath), | ||
storageProvider: storageProvider || new storage_provider_file_1.default(backupPath), | ||
}); | ||
@@ -198,3 +198,6 @@ _this.repository.on(events_2.UnleashEvents.Ready, function () { | ||
Unleash.getInstance = function (config) { | ||
var configSignature = (0, helpers_1.generateHashOfObject)(config); | ||
var cleanConfig = __assign(__assign({}, config), { | ||
// Remove complex objects | ||
repository: undefined, customHeadersFunction: undefined, storageProvider: undefined }); | ||
var configSignature = (0, helpers_1.generateHashOfConfig)(cleanConfig); | ||
if (Unleash.instance) { | ||
@@ -201,0 +204,0 @@ if (configSignature !== Unleash.configSignature) { |
{ | ||
"name": "unleash-client", | ||
"version": "3.18.0", | ||
"version": "3.18.1", | ||
"description": "Unleash Client for Node", | ||
@@ -52,3 +52,3 @@ "license": "Apache-2.0", | ||
"@types/semver": "7.3.13", | ||
"@typescript-eslint/eslint-plugin": "5.48.2", | ||
"@typescript-eslint/eslint-plugin": "5.51.0", | ||
"@unleash/client-specification": "4.2.2", | ||
@@ -55,0 +55,0 @@ "ava": "3.15.0", |
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
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
279329
144
3502