2021-09-13 10:23:57 +02:00
|
|
|
import { Knex } from 'knex';
|
|
|
|
import metricsHelper from '../util/metrics-helper';
|
|
|
|
import { DB_TIME } from '../metric-events';
|
|
|
|
import { Logger, LogProvider } from '../logger';
|
|
|
|
import {
|
|
|
|
IFeatureToggleClient,
|
2023-04-21 11:09:07 +02:00
|
|
|
IFeatureToggleClientStore,
|
2021-09-13 10:23:57 +02:00
|
|
|
IFeatureToggleQuery,
|
|
|
|
IStrategyConfig,
|
2022-11-15 11:24:36 +01:00
|
|
|
ITag,
|
2023-04-21 11:09:07 +02:00
|
|
|
PartialDeep,
|
|
|
|
} from '../types';
|
|
|
|
import { DEFAULT_ENV, ensureStringValue, mapValues } from '../util';
|
Complete open api schemas for project features controller (#1563)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* revert
* revert
* revert
* revert
* revert
* mapper
* revert
* revert
* revert
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* revert
* revert
* add mappers
* add mappers
* fix pr comments
* ignore report.json
* ignore report.json
* Route permission required
Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
|
|
|
import EventEmitter from 'events';
|
2022-07-01 13:51:26 +02:00
|
|
|
import FeatureToggleStore from './feature-toggle-store';
|
2023-01-30 09:02:44 +01:00
|
|
|
import { Db } from './db';
|
2023-04-21 11:09:07 +02:00
|
|
|
import Raw = Knex.Raw;
|
2021-09-13 10:23:57 +02:00
|
|
|
|
2022-11-29 16:06:08 +01:00
|
|
|
export interface IGetAllFeatures {
|
|
|
|
featureQuery?: IFeatureToggleQuery;
|
|
|
|
archived: boolean;
|
2023-07-05 09:32:42 +02:00
|
|
|
requestType: 'client' | 'admin' | 'playground';
|
2022-11-29 16:06:08 +01:00
|
|
|
userId?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IGetAdminFeatures {
|
|
|
|
featureQuery?: IFeatureToggleQuery;
|
|
|
|
archived?: boolean;
|
|
|
|
userId?: number;
|
|
|
|
}
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
export default class FeatureToggleClientStore
|
|
|
|
implements IFeatureToggleClientStore
|
|
|
|
{
|
2023-01-30 09:02:44 +01:00
|
|
|
private db: Db;
|
2021-09-13 10:23:57 +02:00
|
|
|
|
|
|
|
private logger: Logger;
|
|
|
|
|
|
|
|
private timer: Function;
|
|
|
|
|
2023-03-07 14:56:20 +01:00
|
|
|
constructor(db: Db, eventBus: EventEmitter, getLogger: LogProvider) {
|
2021-09-13 10:23:57 +02:00
|
|
|
this.db = db;
|
|
|
|
this.logger = getLogger('feature-toggle-client-store.ts');
|
|
|
|
this.timer = (action) =>
|
|
|
|
metricsHelper.wrapTimer(eventBus, DB_TIME, {
|
|
|
|
store: 'feature-toggle',
|
|
|
|
action,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-29 16:06:08 +01:00
|
|
|
private async getAll({
|
|
|
|
featureQuery,
|
|
|
|
archived,
|
2023-07-05 09:32:42 +02:00
|
|
|
requestType,
|
2022-11-29 16:06:08 +01:00
|
|
|
userId,
|
|
|
|
}: IGetAllFeatures): Promise<IFeatureToggleClient[]> {
|
2023-07-05 09:32:42 +02:00
|
|
|
const isAdmin = requestType === 'admin';
|
|
|
|
const isPlayground = requestType === 'playground';
|
2021-09-24 13:55:00 +02:00
|
|
|
const environment = featureQuery?.environment || DEFAULT_ENV;
|
2021-09-13 10:23:57 +02:00
|
|
|
const stopTimer = this.timer('getFeatureAdmin');
|
2022-03-29 14:59:14 +02:00
|
|
|
|
|
|
|
let selectColumns = [
|
|
|
|
'features.name as name',
|
|
|
|
'features.description as description',
|
|
|
|
'features.type as type',
|
|
|
|
'features.project as project',
|
|
|
|
'features.stale as stale',
|
|
|
|
'features.impression_data as impression_data',
|
2022-11-21 10:37:16 +01:00
|
|
|
'fe.variants as variants',
|
2022-03-29 14:59:14 +02:00
|
|
|
'features.created_at as created_at',
|
|
|
|
'features.last_seen_at as last_seen_at',
|
|
|
|
'fe.enabled as enabled',
|
|
|
|
'fe.environment as environment',
|
|
|
|
'fs.id as strategy_id',
|
|
|
|
'fs.strategy_name as strategy_name',
|
2023-06-29 10:38:51 +02:00
|
|
|
'fs.title as strategy_title',
|
2023-04-21 11:09:07 +02:00
|
|
|
'fs.disabled as strategy_disabled',
|
2022-03-29 14:59:14 +02:00
|
|
|
'fs.parameters as parameters',
|
|
|
|
'fs.constraints as constraints',
|
2022-05-30 09:10:20 +02:00
|
|
|
'segments.id as segment_id',
|
|
|
|
'segments.constraints as segment_constraints',
|
2022-11-30 12:41:53 +01:00
|
|
|
] as (string | Raw<any>)[];
|
2022-03-29 14:59:14 +02:00
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
let query = this.db('features')
|
2022-07-01 13:51:26 +02:00
|
|
|
.modify(FeatureToggleStore.filterByArchived, archived)
|
2022-08-10 08:56:57 +02:00
|
|
|
.leftJoin(
|
2021-10-01 12:27:05 +02:00
|
|
|
this.db('feature_strategies')
|
|
|
|
.select('*')
|
|
|
|
.where({ environment })
|
|
|
|
.as('fs'),
|
|
|
|
'fs.feature_name',
|
|
|
|
'features.name',
|
|
|
|
)
|
2022-08-10 08:56:57 +02:00
|
|
|
.leftJoin(
|
2021-10-01 12:27:05 +02:00
|
|
|
this.db('feature_environments')
|
2022-11-21 10:37:16 +01:00
|
|
|
.select(
|
|
|
|
'feature_name',
|
|
|
|
'enabled',
|
|
|
|
'environment',
|
|
|
|
'variants',
|
|
|
|
)
|
2021-10-01 12:27:05 +02:00
|
|
|
.where({ environment })
|
|
|
|
.as('fe'),
|
|
|
|
'fe.feature_name',
|
2021-09-13 10:23:57 +02:00
|
|
|
'features.name',
|
2022-05-30 09:10:20 +02:00
|
|
|
)
|
2022-07-18 09:30:04 +02:00
|
|
|
.leftJoin(
|
2022-05-30 09:10:20 +02:00
|
|
|
'feature_strategy_segment as fss',
|
|
|
|
`fss.feature_strategy_id`,
|
|
|
|
`fs.id`,
|
|
|
|
)
|
2022-07-14 13:11:22 +02:00
|
|
|
.leftJoin('segments', `segments.id`, `fss.segment_id`);
|
2022-03-29 14:59:14 +02:00
|
|
|
|
2022-11-29 16:06:08 +01:00
|
|
|
if (isAdmin) {
|
2022-12-12 14:21:12 +01:00
|
|
|
query = query.leftJoin(
|
|
|
|
'feature_tag as ft',
|
|
|
|
'ft.feature_name',
|
|
|
|
'features.name',
|
|
|
|
);
|
|
|
|
selectColumns = [
|
|
|
|
...selectColumns,
|
|
|
|
'ft.tag_value as tag_value',
|
|
|
|
'ft.tag_type as tag_type',
|
|
|
|
];
|
2022-11-29 16:06:08 +01:00
|
|
|
|
2022-12-21 13:03:06 +01:00
|
|
|
if (userId) {
|
2022-11-30 12:41:53 +01:00
|
|
|
query = query.leftJoin(`favorite_features`, function () {
|
|
|
|
this.on(
|
|
|
|
'favorite_features.feature',
|
|
|
|
'features.name',
|
|
|
|
).andOnVal('favorite_features.user_id', '=', userId);
|
2022-11-29 16:06:08 +01:00
|
|
|
});
|
2022-11-30 12:41:53 +01:00
|
|
|
selectColumns = [
|
|
|
|
...selectColumns,
|
|
|
|
this.db.raw(
|
|
|
|
'favorite_features.feature is not null as favorite',
|
|
|
|
),
|
|
|
|
];
|
2022-11-29 16:06:08 +01:00
|
|
|
}
|
2022-11-15 11:24:36 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 16:06:08 +01:00
|
|
|
query = query.select(selectColumns);
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
if (featureQuery) {
|
|
|
|
if (featureQuery.tag) {
|
|
|
|
const tagQuery = this.db
|
|
|
|
.from('feature_tag')
|
|
|
|
.select('feature_name')
|
|
|
|
.whereIn(['tag_type', 'tag_value'], featureQuery.tag);
|
2022-03-29 14:59:14 +02:00
|
|
|
query = query.whereIn('features.name', tagQuery);
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
|
|
|
if (featureQuery.project) {
|
|
|
|
query = query.whereIn('project', featureQuery.project);
|
|
|
|
}
|
|
|
|
if (featureQuery.namePrefix) {
|
|
|
|
query = query.where(
|
2022-03-29 14:59:14 +02:00
|
|
|
'features.name',
|
2021-09-13 10:23:57 +02:00
|
|
|
'like',
|
|
|
|
`${featureQuery.namePrefix}%`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-10-01 12:27:05 +02:00
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
const rows = await query;
|
|
|
|
stopTimer();
|
2022-03-29 14:59:14 +02:00
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
const featureToggles = rows.reduce((acc, r) => {
|
2022-03-29 14:59:14 +02:00
|
|
|
let feature: PartialDeep<IFeatureToggleClient> = acc[r.name] ?? {
|
|
|
|
strategies: [],
|
|
|
|
};
|
2023-05-08 10:42:26 +02:00
|
|
|
if (this.isUnseenStrategyRow(feature, r) && !r.strategy_disabled) {
|
2023-04-21 11:09:07 +02:00
|
|
|
feature.strategies?.push(
|
Complete open api schemas for project features controller (#1563)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* revert
* revert
* revert
* revert
* revert
* mapper
* revert
* revert
* revert
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* revert
* revert
* add mappers
* add mappers
* fix pr comments
* ignore report.json
* ignore report.json
* Route permission required
Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
|
|
|
FeatureToggleClientStore.rowToStrategy(r),
|
|
|
|
);
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
2022-11-15 11:24:36 +01:00
|
|
|
if (this.isNewTag(feature, r)) {
|
|
|
|
this.addTag(feature, r);
|
|
|
|
}
|
2022-06-02 14:07:46 +02:00
|
|
|
if (featureQuery?.inlineSegmentConstraints && r.segment_id) {
|
2022-03-29 14:59:14 +02:00
|
|
|
this.addSegmentToStrategy(feature, r);
|
2022-06-02 14:07:46 +02:00
|
|
|
} else if (
|
|
|
|
!featureQuery?.inlineSegmentConstraints &&
|
|
|
|
r.segment_id
|
|
|
|
) {
|
2022-05-30 09:10:20 +02:00
|
|
|
this.addSegmentIdsToStrategy(feature, r);
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
2022-02-03 11:06:51 +01:00
|
|
|
feature.impressionData = r.impression_data;
|
2021-10-01 12:27:05 +02:00
|
|
|
feature.enabled = !!r.enabled;
|
2021-09-13 10:23:57 +02:00
|
|
|
feature.name = r.name;
|
|
|
|
feature.description = r.description;
|
|
|
|
feature.project = r.project;
|
|
|
|
feature.stale = r.stale;
|
|
|
|
feature.type = r.type;
|
2022-11-21 10:37:16 +01:00
|
|
|
feature.variants = r.variants || [];
|
2021-09-13 10:23:57 +02:00
|
|
|
feature.project = r.project;
|
|
|
|
if (isAdmin) {
|
2023-03-08 14:56:51 +01:00
|
|
|
feature.favorite = r.favorite;
|
2021-09-13 10:23:57 +02:00
|
|
|
feature.lastSeenAt = r.last_seen_at;
|
|
|
|
feature.createdAt = r.created_at;
|
|
|
|
}
|
2023-06-29 10:38:51 +02:00
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
acc[r.name] = feature;
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2022-03-29 14:59:14 +02:00
|
|
|
|
|
|
|
const features: IFeatureToggleClient[] = Object.values(featureToggles);
|
|
|
|
|
2023-06-29 10:38:51 +02:00
|
|
|
// strip away unwanted properties
|
|
|
|
const cleanedFeatures = features.map(({ strategies, ...rest }) => ({
|
|
|
|
...rest,
|
|
|
|
strategies: strategies?.map(({ id, title, ...strategy }) => ({
|
|
|
|
...strategy,
|
|
|
|
|
2023-07-05 09:32:42 +02:00
|
|
|
...(isPlayground && title ? { title } : {}),
|
2023-06-29 10:38:51 +02:00
|
|
|
|
|
|
|
// We should not send strategy IDs from the client API,
|
|
|
|
// as this breaks old versions of the Go SDK (at least).
|
2023-07-05 09:32:42 +02:00
|
|
|
...(isAdmin || isPlayground ? { id } : {}),
|
2023-06-29 10:38:51 +02:00
|
|
|
})),
|
|
|
|
}));
|
2022-03-29 14:59:14 +02:00
|
|
|
|
2023-06-29 10:38:51 +02:00
|
|
|
return cleanedFeatures;
|
2022-03-29 14:59:14 +02:00
|
|
|
}
|
|
|
|
|
Complete open api schemas for project features controller (#1563)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* Completed OpenAPI Schemas for ProjectFeatures Controller
Completed OpenAPI Schemas for Feature Controller (tags)
* bug fix
* bug fix
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* fix merge conflicts, some refactoring
* added emptyResponse, patch feature operation schemas and request
* added emptyResponse, patch feature operation schemas and request
* patch strategy
* patch strategy
* update strategy
* update strategy
* fix pr comment
* fix pr comments
* improvements
* added operationId to schema for better generation
* fix pr comment
* fix pr comment
* fix pr comment
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* improvements to generated and dynamic types
* Update response types to use inferred types
* Update addTag response status to 201
* refactor: move schema ref destructuring into createSchemaObject
* made serialize date handle deep objects
* made serialize date handle deep objects
* add `name` to IFeatureStrategy nad fix tests
* fix pr comments
* fix pr comments
* Add types to IAuthRequest
* Sync StrategySchema for FE and BE - into the rabbit hole
* Sync model with OAS spec
* revert
* revert
* revert
* revert
* revert
* mapper
* revert
* revert
* revert
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* remove serialize-dates.ts
* revert
* revert
* add mappers
* add mappers
* fix pr comments
* ignore report.json
* ignore report.json
* Route permission required
Co-authored-by: olav <mail@olav.io>
2022-05-18 15:17:09 +02:00
|
|
|
private static rowToStrategy(row: Record<string, any>): IStrategyConfig {
|
2022-03-29 14:59:14 +02:00
|
|
|
return {
|
|
|
|
id: row.strategy_id,
|
|
|
|
name: row.strategy_name,
|
2023-04-21 11:09:07 +02:00
|
|
|
title: row.strategy_title,
|
2022-03-29 14:59:14 +02:00
|
|
|
constraints: row.constraints || [],
|
2022-06-29 10:11:34 +02:00
|
|
|
parameters: mapValues(row.parameters || {}, ensureStringValue),
|
2022-03-29 14:59:14 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-15 11:24:36 +01:00
|
|
|
private static rowToTag(row: Record<string, any>): ITag {
|
|
|
|
return {
|
|
|
|
value: row.tag_value,
|
|
|
|
type: row.tag_type,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-29 14:59:14 +02:00
|
|
|
private isUnseenStrategyRow(
|
|
|
|
feature: PartialDeep<IFeatureToggleClient>,
|
|
|
|
row: Record<string, any>,
|
|
|
|
): boolean {
|
|
|
|
return (
|
|
|
|
row.strategy_id &&
|
2023-04-21 11:09:07 +02:00
|
|
|
!feature.strategies?.find((s) => s?.id === row.strategy_id)
|
2022-03-29 14:59:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-15 11:24:36 +01:00
|
|
|
private addTag(
|
|
|
|
feature: Record<string, any>,
|
|
|
|
row: Record<string, any>,
|
|
|
|
): void {
|
|
|
|
const tags = feature.tags || [];
|
|
|
|
const newTag = FeatureToggleClientStore.rowToTag(row);
|
|
|
|
feature.tags = [...tags, newTag];
|
|
|
|
}
|
|
|
|
|
|
|
|
private isNewTag(
|
|
|
|
feature: PartialDeep<IFeatureToggleClient>,
|
|
|
|
row: Record<string, any>,
|
|
|
|
): boolean {
|
|
|
|
return (
|
|
|
|
row.tag_type &&
|
|
|
|
row.tag_value &&
|
|
|
|
!feature.tags?.some(
|
|
|
|
(tag) =>
|
2023-04-21 11:09:07 +02:00
|
|
|
tag?.type === row.tag_type && tag?.value === row.tag_value,
|
2022-11-15 11:24:36 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-29 14:59:14 +02:00
|
|
|
private addSegmentToStrategy(
|
|
|
|
feature: PartialDeep<IFeatureToggleClient>,
|
|
|
|
row: Record<string, any>,
|
|
|
|
) {
|
|
|
|
feature.strategies
|
2023-04-21 11:09:07 +02:00
|
|
|
?.find((s) => s?.id === row.strategy_id)
|
|
|
|
?.constraints?.push(...row.segment_constraints);
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
|
|
|
|
2022-05-30 09:10:20 +02:00
|
|
|
private addSegmentIdsToStrategy(
|
|
|
|
feature: PartialDeep<IFeatureToggleClient>,
|
|
|
|
row: Record<string, any>,
|
|
|
|
) {
|
2023-04-21 11:09:07 +02:00
|
|
|
const strategy = feature.strategies?.find(
|
|
|
|
(s) => s?.id === row.strategy_id,
|
2022-05-30 09:10:20 +02:00
|
|
|
);
|
|
|
|
if (!strategy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!strategy.segments) {
|
|
|
|
strategy.segments = [];
|
|
|
|
}
|
|
|
|
strategy.segments.push(row.segment_id);
|
|
|
|
}
|
|
|
|
|
2021-09-13 10:23:57 +02:00
|
|
|
async getClient(
|
|
|
|
featureQuery?: IFeatureToggleQuery,
|
|
|
|
): Promise<IFeatureToggleClient[]> {
|
2022-11-29 16:06:08 +01:00
|
|
|
return this.getAll({
|
|
|
|
featureQuery,
|
|
|
|
archived: false,
|
2023-07-05 09:32:42 +02:00
|
|
|
requestType: 'client',
|
2023-06-29 10:38:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getPlayground(
|
|
|
|
featureQuery?: IFeatureToggleQuery,
|
|
|
|
): Promise<IFeatureToggleClient[]> {
|
|
|
|
return this.getAll({
|
|
|
|
featureQuery,
|
|
|
|
archived: false,
|
2023-07-05 09:32:42 +02:00
|
|
|
requestType: 'playground',
|
2022-11-29 16:06:08 +01:00
|
|
|
});
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
|
|
|
|
2022-11-29 16:06:08 +01:00
|
|
|
async getAdmin({
|
|
|
|
featureQuery,
|
|
|
|
userId,
|
|
|
|
archived,
|
|
|
|
}: IGetAdminFeatures): Promise<IFeatureToggleClient[]> {
|
2023-04-21 11:09:07 +02:00
|
|
|
return this.getAll({
|
|
|
|
featureQuery,
|
|
|
|
archived: Boolean(archived),
|
2023-07-05 09:32:42 +02:00
|
|
|
requestType: 'admin',
|
2023-04-21 11:09:07 +02:00
|
|
|
userId,
|
|
|
|
});
|
2021-09-13 10:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FeatureToggleClientStore;
|