diff --git a/CHANGELOG.md b/CHANGELOG.md index 185c46c49b..89e4935549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.10.1 + +- fix: remove fields from /api/client/features respnse (#692) + ## 3.10.0 - feat: add tags (#655) @@ -11,7 +15,6 @@ - fix: Updated docs about event-types (#684) - fix: Add application-created event (#595) - ## 3.9.0 - fix: stateService undefined diff --git a/lib/db/feature-toggle-store.js b/lib/db/feature-toggle-store.js index 4c773f9f46..b18b562802 100644 --- a/lib/db/feature-toggle-store.js +++ b/lib/db/feature-toggle-store.js @@ -18,6 +18,15 @@ const FEATURE_COLUMNS = [ ]; const TABLE = 'features'; +const FEATURE_COLUMNS_CLIENT = [ + 'name', + 'type', + 'enabled', + 'stale', + 'strategies', + 'variants', +]; + class FeatureToggleStore { constructor(db, eventBus, getLogger) { this.db = db; @@ -43,6 +52,34 @@ class FeatureToggleStore { return rows.map(this.rowToFeature); } + async getFeaturesClient() { + const stopTimer = this.timer('getAllClient'); + + const rows = await this.db + .select(FEATURE_COLUMNS_CLIENT) + .from(TABLE) + .where({ archived: 0 }) + .orderBy('name', 'asc'); + + stopTimer(); + + return rows.map(this.rowToFeature); + } + + async getClientFeatures() { + const stopTimer = this.timer('getAll'); + + const rows = await this.db + .select(FEATURE_COLUMNS) + .from(TABLE) + .where({ archived: 0 }) + .orderBy('name', 'asc'); + + stopTimer(); + + return rows.map(this.rowToFeature); + } + async getFeaturesBy(fields) { const rows = await this.db .select(FEATURE_COLUMNS) diff --git a/lib/routes/client-api/feature.js b/lib/routes/client-api/feature.js index 0cfed78151..08a49b5a08 100644 --- a/lib/routes/client-api/feature.js +++ b/lib/routes/client-api/feature.js @@ -17,7 +17,7 @@ class FeatureController extends Controller { async getAll(req, res) { const nameFilter = filter('name', req.query.namePrefix); - const allFeatureToggles = await this.toggleService.getFeatures(); + const allFeatureToggles = await this.toggleService.getFeaturesClient(); const features = nameFilter(allFeatureToggles); res.json({ version, features }); diff --git a/lib/services/feature-toggle-service.js b/lib/services/feature-toggle-service.js index 51f3c5c79b..aeba89a431 100644 --- a/lib/services/feature-toggle-service.js +++ b/lib/services/feature-toggle-service.js @@ -27,6 +27,10 @@ class FeatureToggleService { return this.featureToggleStore.getFeatures(); } + async getFeaturesClient() { + return this.featureToggleStore.getFeaturesClient(); + } + async getArchivedFeatures() { return this.featureToggleStore.getArchivedFeatures(); } diff --git a/test/e2e/api/client/feature.e2e.test.js b/test/e2e/api/client/feature.e2e.test.js index 639fbbb375..a6373b6052 100644 --- a/test/e2e/api/client/feature.e2e.test.js +++ b/test/e2e/api/client/feature.e2e.test.js @@ -23,7 +23,18 @@ test.serial('returns four feature toggles', async t => { .expect('Content-Type', /json/) .expect(200) .expect(res => { - t.true(res.body.features.length === 4); + t.is(res.body.features.length, 4); + }); +}); + +test.serial('returns four feature toggles without createdAt', async t => { + const request = await setupApp(stores); + return request + .get('/api/client/features') + .expect('Content-Type', /json/) + .expect(200) + .expect(res => { + t.falsy(res.body.features[0].createdAt); }); }); diff --git a/test/fixtures/fake-feature-toggle-store.js b/test/fixtures/fake-feature-toggle-store.js index 1659c1b5db..67d8477646 100644 --- a/test/fixtures/fake-feature-toggle-store.js +++ b/test/fixtures/fake-feature-toggle-store.js @@ -30,6 +30,7 @@ module.exports = () => { _features.push(updatedFeature); }, getFeatures: () => Promise.resolve(_features), + getFeaturesClient: () => Promise.resolve(_features), createFeature: feature => _features.push(feature), getArchivedFeatures: () => Promise.resolve(_archive), addArchivedFeature: feature => _archive.push(feature),