@spotify-confidence/client-http
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -8,4 +8,3 @@ import { ConfidenceClient } from './client'; | ||
export declare class ApplyManager { | ||
private resolveTokenPending; | ||
private resolveTokenSeen; | ||
private readonly tokenRecords; | ||
private readonly timeout; | ||
@@ -18,3 +17,4 @@ private readonly maxBufferSize; | ||
apply(resolveToken: string, flagName: string): void; | ||
private getTokenRecord; | ||
} | ||
//# sourceMappingURL=ApplyManager.d.ts.map |
@@ -15,4 +15,3 @@ "use strict"; | ||
constructor(options) { | ||
this.resolveTokenPending = new Map(); | ||
this.resolveTokenSeen = new Map(); | ||
this.tokenRecords = new Map(); | ||
this.flushTimeout = null; | ||
@@ -25,14 +24,9 @@ this.timeout = options.timeout; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const resolve_token of Array.from(this.resolveTokenPending.keys())) { | ||
const flagsToSend = this.resolveTokenPending.get(resolve_token) || []; | ||
if (flagsToSend.length === 0) { | ||
for (const [resolve_token, { pendingApply }] of Array.from(this.tokenRecords.entries())) { | ||
if (!pendingApply.length) | ||
continue; | ||
} | ||
try { | ||
this.client.apply(flagsToSend, resolve_token).then(() => { | ||
this.resolveTokenPending.set(resolve_token, []); | ||
}); | ||
} | ||
catch (e) { | ||
} | ||
const flagsToSend = pendingApply.splice(0, pendingApply.length); | ||
this.client.apply(flagsToSend, resolve_token).catch(() => { | ||
pendingApply.push(...flagsToSend); | ||
}); | ||
} | ||
@@ -42,26 +36,16 @@ }); | ||
apply(resolveToken, flagName) { | ||
var _a, _b, _c, _d; | ||
if (!resolveToken) { | ||
if (!resolveToken) | ||
return; | ||
} | ||
const confidenceFlagName = `flags/${flagName}`; | ||
if ((_a = this.resolveTokenSeen.get(resolveToken)) === null || _a === void 0 ? void 0 : _a.has(flagName)) { | ||
const tokenRecord = this.getTokenRecord(resolveToken); | ||
if (tokenRecord.seenFlags.has(flagName)) | ||
return; | ||
} | ||
const appliedFlag = { | ||
flag: confidenceFlagName, | ||
tokenRecord.seenFlags.add(flagName); | ||
tokenRecord.pendingApply.push({ | ||
flag: `flags/${flagName}`, | ||
applyTime: new Date().toISOString(), | ||
}; | ||
if (!this.resolveTokenPending.has(resolveToken)) { | ||
this.resolveTokenPending.set(resolveToken, [appliedFlag]); | ||
this.resolveTokenSeen.set(resolveToken, new Set([flagName])); | ||
} | ||
else { | ||
(_b = this.resolveTokenPending.get(resolveToken)) === null || _b === void 0 ? void 0 : _b.push(appliedFlag); | ||
(_c = this.resolveTokenSeen.get(resolveToken)) === null || _c === void 0 ? void 0 : _c.add(confidenceFlagName); | ||
} | ||
}); | ||
if (this.flushTimeout) { | ||
clearTimeout(this.flushTimeout); | ||
} | ||
if ((((_d = this.resolveTokenPending.get(resolveToken)) === null || _d === void 0 ? void 0 : _d.length) || 0) >= this.maxBufferSize) { | ||
if (tokenRecord.pendingApply.length >= this.maxBufferSize) { | ||
this.flush(); | ||
@@ -73,4 +57,11 @@ } | ||
} | ||
getTokenRecord(resolveToken) { | ||
let tokenRecord = this.tokenRecords.get(resolveToken); | ||
if (!tokenRecord) { | ||
this.tokenRecords.set(resolveToken, (tokenRecord = { pendingApply: [], seenFlags: new Set() })); | ||
} | ||
return tokenRecord; | ||
} | ||
} | ||
exports.ApplyManager = ApplyManager; | ||
//# sourceMappingURL=ApplyManager.js.map |
@@ -8,4 +8,3 @@ import { ConfidenceClient } from './client'; | ||
export declare class ApplyManager { | ||
private resolveTokenPending; | ||
private resolveTokenSeen; | ||
private readonly tokenRecords; | ||
private readonly timeout; | ||
@@ -18,3 +17,4 @@ private readonly maxBufferSize; | ||
apply(resolveToken: string, flagName: string): void; | ||
private getTokenRecord; | ||
} | ||
//# sourceMappingURL=ApplyManager.d.ts.map |
@@ -12,4 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor(options) { | ||
this.resolveTokenPending = new Map(); | ||
this.resolveTokenSeen = new Map(); | ||
this.tokenRecords = new Map(); | ||
this.flushTimeout = null; | ||
@@ -22,14 +21,9 @@ this.timeout = options.timeout; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const resolve_token of Array.from(this.resolveTokenPending.keys())) { | ||
const flagsToSend = this.resolveTokenPending.get(resolve_token) || []; | ||
if (flagsToSend.length === 0) { | ||
for (const [resolve_token, { pendingApply }] of Array.from(this.tokenRecords.entries())) { | ||
if (!pendingApply.length) | ||
continue; | ||
} | ||
try { | ||
this.client.apply(flagsToSend, resolve_token).then(() => { | ||
this.resolveTokenPending.set(resolve_token, []); | ||
}); | ||
} | ||
catch (e) { | ||
} | ||
const flagsToSend = pendingApply.splice(0, pendingApply.length); | ||
this.client.apply(flagsToSend, resolve_token).catch(() => { | ||
pendingApply.push(...flagsToSend); | ||
}); | ||
} | ||
@@ -39,26 +33,16 @@ }); | ||
apply(resolveToken, flagName) { | ||
var _a, _b, _c, _d; | ||
if (!resolveToken) { | ||
if (!resolveToken) | ||
return; | ||
} | ||
const confidenceFlagName = `flags/${flagName}`; | ||
if ((_a = this.resolveTokenSeen.get(resolveToken)) === null || _a === void 0 ? void 0 : _a.has(flagName)) { | ||
const tokenRecord = this.getTokenRecord(resolveToken); | ||
if (tokenRecord.seenFlags.has(flagName)) | ||
return; | ||
} | ||
const appliedFlag = { | ||
flag: confidenceFlagName, | ||
tokenRecord.seenFlags.add(flagName); | ||
tokenRecord.pendingApply.push({ | ||
flag: `flags/${flagName}`, | ||
applyTime: new Date().toISOString(), | ||
}; | ||
if (!this.resolveTokenPending.has(resolveToken)) { | ||
this.resolveTokenPending.set(resolveToken, [appliedFlag]); | ||
this.resolveTokenSeen.set(resolveToken, new Set([flagName])); | ||
} | ||
else { | ||
(_b = this.resolveTokenPending.get(resolveToken)) === null || _b === void 0 ? void 0 : _b.push(appliedFlag); | ||
(_c = this.resolveTokenSeen.get(resolveToken)) === null || _c === void 0 ? void 0 : _c.add(confidenceFlagName); | ||
} | ||
}); | ||
if (this.flushTimeout) { | ||
clearTimeout(this.flushTimeout); | ||
} | ||
if ((((_d = this.resolveTokenPending.get(resolveToken)) === null || _d === void 0 ? void 0 : _d.length) || 0) >= this.maxBufferSize) { | ||
if (tokenRecord.pendingApply.length >= this.maxBufferSize) { | ||
this.flush(); | ||
@@ -70,3 +54,10 @@ } | ||
} | ||
getTokenRecord(resolveToken) { | ||
let tokenRecord = this.tokenRecords.get(resolveToken); | ||
if (!tokenRecord) { | ||
this.tokenRecords.set(resolveToken, (tokenRecord = { pendingApply: [], seenFlags: new Set() })); | ||
} | ||
return tokenRecord; | ||
} | ||
} | ||
//# sourceMappingURL=ApplyManager.js.map |
@@ -8,4 +8,3 @@ import { ConfidenceClient } from './client'; | ||
export declare class ApplyManager { | ||
private resolveTokenPending; | ||
private resolveTokenSeen; | ||
private readonly tokenRecords; | ||
private readonly timeout; | ||
@@ -18,3 +17,4 @@ private readonly maxBufferSize; | ||
apply(resolveToken: string, flagName: string): void; | ||
private getTokenRecord; | ||
} | ||
//# sourceMappingURL=ApplyManager.d.ts.map |
@@ -12,4 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor(options) { | ||
this.resolveTokenPending = new Map(); | ||
this.resolveTokenSeen = new Map(); | ||
this.tokenRecords = new Map(); | ||
this.flushTimeout = null; | ||
@@ -22,14 +21,9 @@ this.timeout = options.timeout; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const resolve_token of Array.from(this.resolveTokenPending.keys())) { | ||
const flagsToSend = this.resolveTokenPending.get(resolve_token) || []; | ||
if (flagsToSend.length === 0) { | ||
for (const [resolve_token, { pendingApply }] of Array.from(this.tokenRecords.entries())) { | ||
if (!pendingApply.length) | ||
continue; | ||
} | ||
try { | ||
this.client.apply(flagsToSend, resolve_token).then(() => { | ||
this.resolveTokenPending.set(resolve_token, []); | ||
}); | ||
} | ||
catch (e) { | ||
} | ||
const flagsToSend = pendingApply.splice(0, pendingApply.length); | ||
this.client.apply(flagsToSend, resolve_token).catch(() => { | ||
pendingApply.push(...flagsToSend); | ||
}); | ||
} | ||
@@ -39,26 +33,16 @@ }); | ||
apply(resolveToken, flagName) { | ||
var _a, _b, _c, _d; | ||
if (!resolveToken) { | ||
if (!resolveToken) | ||
return; | ||
} | ||
const confidenceFlagName = `flags/${flagName}`; | ||
if ((_a = this.resolveTokenSeen.get(resolveToken)) === null || _a === void 0 ? void 0 : _a.has(flagName)) { | ||
const tokenRecord = this.getTokenRecord(resolveToken); | ||
if (tokenRecord.seenFlags.has(flagName)) | ||
return; | ||
} | ||
const appliedFlag = { | ||
flag: confidenceFlagName, | ||
tokenRecord.seenFlags.add(flagName); | ||
tokenRecord.pendingApply.push({ | ||
flag: `flags/${flagName}`, | ||
applyTime: new Date().toISOString(), | ||
}; | ||
if (!this.resolveTokenPending.has(resolveToken)) { | ||
this.resolveTokenPending.set(resolveToken, [appliedFlag]); | ||
this.resolveTokenSeen.set(resolveToken, new Set([flagName])); | ||
} | ||
else { | ||
(_b = this.resolveTokenPending.get(resolveToken)) === null || _b === void 0 ? void 0 : _b.push(appliedFlag); | ||
(_c = this.resolveTokenSeen.get(resolveToken)) === null || _c === void 0 ? void 0 : _c.add(confidenceFlagName); | ||
} | ||
}); | ||
if (this.flushTimeout) { | ||
clearTimeout(this.flushTimeout); | ||
} | ||
if ((((_d = this.resolveTokenPending.get(resolveToken)) === null || _d === void 0 ? void 0 : _d.length) || 0) >= this.maxBufferSize) { | ||
if (tokenRecord.pendingApply.length >= this.maxBufferSize) { | ||
this.flush(); | ||
@@ -70,3 +54,10 @@ } | ||
} | ||
getTokenRecord(resolveToken) { | ||
let tokenRecord = this.tokenRecords.get(resolveToken); | ||
if (!tokenRecord) { | ||
this.tokenRecords.set(resolveToken, (tokenRecord = { pendingApply: [], seenFlags: new Set() })); | ||
} | ||
return tokenRecord; | ||
} | ||
} | ||
//# sourceMappingURL=ApplyManager.js.map |
# Changelog | ||
## [0.1.3](https://github.com/spotify/confidence-openfeature-provider-js/compare/client-http-v0.1.2...client-http-v0.1.3) (2024-01-22) | ||
### 🐛 Bug Fixes | ||
* **client-http:** duplicate events on buffer overflow ([57ff968](https://github.com/spotify/confidence-openfeature-provider-js/commit/57ff9680931a11ee4db9fe80e54592e878bc21eb)) | ||
## [0.1.2](https://github.com/spotify/confidence-openfeature-provider-js/compare/client-http-v0.1.1...client-http-v0.1.2) (2024-01-05) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@spotify-confidence/client-http", | ||
"license": "Apache-2.0", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"module": "build/esm/index.js", | ||
@@ -17,3 +17,3 @@ "main": "build/cjs/index.js", | ||
}, | ||
"gitHead": "46e0ddd79f7b5b3cdff630f773ff4c1f3009ec9c" | ||
"gitHead": "bf00676216a4c9ca3f59ac01d5bf444ab5c24f85" | ||
} |
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
197493
1073