@devcycle/nodejs-server-sdk
Advanced tools
Comparing version 1.4.12 to 1.4.13
{ | ||
"name": "@devcycle/nodejs-server-sdk", | ||
"version": "1.4.12", | ||
"version": "1.4.13", | ||
"description": "The DevCycle NodeJS Server SDK used for feature management.", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@devcycle/bucketing-test-data": "^1.0.33", | ||
"@devcycle/bucketing-test-data": "^1.0.34", | ||
"assemblyscript-json": "*", | ||
@@ -12,4 +12,4 @@ "assemblyscript-regex": "*" | ||
"dependencies": { | ||
"@devcycle/bucketing-assembly-script": "^1.1.13", | ||
"@devcycle/types": "1.0.45", | ||
"@devcycle/bucketing-assembly-script": "^1.1.14", | ||
"@devcycle/types": "1.0.46", | ||
"class-transformer": "0.5.1", | ||
@@ -16,0 +16,0 @@ "@nestjs/class-validator": "^0.13.4", |
import { DVCOptions, DVCVariableValue, DVCVariable as DVCVariableInterface, DVCVariableSet, DVCFeatureSet, DVCEvent, DVCUser } from './types'; | ||
export declare class DVCClient { | ||
private environmentKey; | ||
private options?; | ||
private configHelper; | ||
@@ -6,0 +5,0 @@ private eventQueue; |
@@ -92,3 +92,2 @@ "use strict"; | ||
this.environmentKey = environmentKey; | ||
this.options = options; | ||
this.logger = (options === null || options === void 0 ? void 0 : options.logger) || (0, logger_1.dvcDefaultLogger)({ level: options === null || options === void 0 ? void 0 : options.logLevel }); | ||
@@ -101,3 +100,3 @@ if (options === null || options === void 0 ? void 0 : options.enableEdgeDB) { | ||
_this.configHelper = new environmentConfigManager_1.EnvironmentConfigManager(_this.logger, environmentKey, options || {}); | ||
_this.eventQueue = new eventQueue_1.EventQueue(_this.logger, environmentKey, options); | ||
_this.eventQueue = new eventQueue_1.EventQueue(environmentKey, __assign(__assign({}, options), { logger: _this.logger })); | ||
var platformData = { | ||
@@ -104,0 +103,0 @@ platform: 'NodeJS', |
import { DVCEvent } from './types'; | ||
import { DVCRequestEvent } from './models/requestEvent'; | ||
import { DVCPopulatedUser } from './models/populatedUser'; | ||
import { BucketedUserConfig, DVCLogger } from '@devcycle/types'; | ||
import { BucketedUserConfig, DVCLogger, DVCReporter } from '@devcycle/types'; | ||
export declare const AggregateEventTypes: Record<string, string>; | ||
@@ -23,5 +23,8 @@ export declare const EventTypes: Record<string, string>; | ||
flushEventQueueSize?: number; | ||
logger: DVCLogger; | ||
reporter?: DVCReporter; | ||
}; | ||
export declare class EventQueue { | ||
private readonly logger; | ||
private readonly reporter?; | ||
private readonly environmentKey; | ||
@@ -33,3 +36,3 @@ eventFlushIntervalMS: number; | ||
private flushInProgress; | ||
constructor(logger: DVCLogger, environmentKey: string, options?: EventQueueOptions); | ||
constructor(environmentKey: string, options: EventQueueOptions); | ||
cleanup(): void; | ||
@@ -36,0 +39,0 @@ /** |
@@ -61,6 +61,6 @@ "use strict"; | ||
var EventQueue = /** @class */ (function () { | ||
function EventQueue(logger, environmentKey, options) { | ||
if (options === void 0) { options = {}; } | ||
function EventQueue(environmentKey, options) { | ||
this.flushInProgress = false; | ||
this.logger = logger; | ||
this.logger = options.logger; | ||
this.reporter = options.reporter; | ||
this.environmentKey = environmentKey; | ||
@@ -101,10 +101,16 @@ this.eventFlushIntervalMS = (options === null || options === void 0 ? void 0 : options.eventFlushIntervalMS) || 10 * 1000; | ||
EventQueue.prototype.flushEvents = function () { | ||
var _a, _b, _c, _d, _e; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var flushPayloadsStr, flushPayloads, reducer, eventCount; | ||
var metricTags, flushPayloadsStr, results, startTimeJson, flushPayloads, endTimeJson, reducer, eventCount, startTimeRequests, endTimeRequests; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
metricTags = { | ||
envKey: this.environmentKey | ||
}; | ||
(_a = this.reporter) === null || _a === void 0 ? void 0 : _a.reportMetric('queueLength', (0, bucketing_1.getBucketingLib)().eventQueueSize(this.environmentKey), metricTags); | ||
try { | ||
flushPayloadsStr = (0, bucketing_1.getBucketingLib)().flushEventQueue(this.environmentKey); | ||
(_b = this.reporter) === null || _b === void 0 ? void 0 : _b.reportMetric('flushPayloadSize', flushPayloadsStr === null || flushPayloadsStr === void 0 ? void 0 : flushPayloadsStr.length, metricTags); | ||
} | ||
@@ -114,6 +120,14 @@ catch (ex) { | ||
} | ||
results = { | ||
failures: 0, | ||
retries: 0, | ||
successes: 0 | ||
}; | ||
if (!flushPayloadsStr) | ||
return [2 /*return*/]; | ||
this.logger.debug("Flush Payloads: ".concat(flushPayloadsStr)); | ||
startTimeJson = Date.now(); | ||
flushPayloads = JSON.parse(flushPayloadsStr); | ||
endTimeJson = Date.now(); | ||
(_c = this.reporter) === null || _c === void 0 ? void 0 : _c.reportMetric('jsonParseDuration', endTimeJson - startTimeJson, metricTags); | ||
if (flushPayloads.length === 0) | ||
@@ -125,2 +139,3 @@ return [2 /*return*/]; | ||
this.flushInProgress = true; | ||
startTimeRequests = Date.now(); | ||
return [4 /*yield*/, Promise.all(flushPayloads.map(function (flushPayload) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -138,5 +153,7 @@ var res, ex_1; | ||
if (res.status >= 500) { | ||
results.retries++; | ||
(0, bucketing_1.getBucketingLib)().onPayloadFailure(this.environmentKey, flushPayload.payloadId, true); | ||
} | ||
else { | ||
results.failures++; | ||
(0, bucketing_1.getBucketingLib)().onPayloadFailure(this.environmentKey, flushPayload.payloadId, false); | ||
@@ -148,2 +165,3 @@ } | ||
(0, bucketing_1.getBucketingLib)().onPayloadSuccess(this.environmentKey, flushPayload.payloadId); | ||
results.successes++; | ||
} | ||
@@ -155,2 +173,3 @@ return [3 /*break*/, 3]; | ||
(0, bucketing_1.getBucketingLib)().onPayloadFailure(this.environmentKey, flushPayload.payloadId, true); | ||
results.retries++; | ||
return [3 /*break*/, 3]; | ||
@@ -162,4 +181,7 @@ case 3: return [2 /*return*/]; | ||
case 1: | ||
_a.sent(); | ||
_f.sent(); | ||
this.flushInProgress = false; | ||
endTimeRequests = Date.now(); | ||
(_d = this.reporter) === null || _d === void 0 ? void 0 : _d.reportMetric('flushRequestDuration', endTimeRequests - startTimeRequests, metricTags); | ||
(_e = this.reporter) === null || _e === void 0 ? void 0 : _e.reportFlushResults(results, metricTags); | ||
return [2 /*return*/]; | ||
@@ -166,0 +188,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { DVCLogger, DVCDefaultLogLevel } from '@devcycle/types'; | ||
import { DVCLogger, DVCDefaultLogLevel, DVCReporter } from '@devcycle/types'; | ||
export interface DVCUser { | ||
@@ -54,2 +54,6 @@ /** | ||
/** | ||
* Metrics reporter to capture data about event processing | ||
*/ | ||
reporter?: DVCReporter; | ||
/** | ||
* Set log level of the default logger | ||
@@ -56,0 +60,0 @@ */ |
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
104218
1561
20227
+ Added@devcycle/types@1.0.46(transitive)
- Removed@devcycle/types@1.0.45(transitive)
Updated@devcycle/types@1.0.46