mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
parent
1ccbce23de
commit
16bca1260c
@ -4,6 +4,7 @@ import { featureStrategySchema } from './feature-strategy-schema';
|
|||||||
import { featureEnvironmentSchema } from './feature-environment-schema';
|
import { featureEnvironmentSchema } from './feature-environment-schema';
|
||||||
import { contextFieldSchema } from './context-field-schema';
|
import { contextFieldSchema } from './context-field-schema';
|
||||||
import { featureTagSchema } from './feature-tag-schema';
|
import { featureTagSchema } from './feature-tag-schema';
|
||||||
|
import { segmentSchema } from './segment-schema';
|
||||||
|
|
||||||
export const exportResultSchema = {
|
export const exportResultSchema = {
|
||||||
$id: '#/components/schemas/exportResultSchema',
|
$id: '#/components/schemas/exportResultSchema',
|
||||||
@ -41,6 +42,12 @@ export const exportResultSchema = {
|
|||||||
$ref: '#/components/schemas/featureTagSchema',
|
$ref: '#/components/schemas/featureTagSchema',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
segments: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
$ref: '#/components/schemas/segmentSchema',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
schemas: {
|
schemas: {
|
||||||
@ -49,6 +56,7 @@ export const exportResultSchema = {
|
|||||||
featureEnvironmentSchema,
|
featureEnvironmentSchema,
|
||||||
contextFieldSchema,
|
contextFieldSchema,
|
||||||
featureTagSchema,
|
featureTagSchema,
|
||||||
|
segmentSchema,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
IFeatureEnvironment,
|
IFeatureEnvironment,
|
||||||
IFeatureStrategy,
|
IFeatureStrategy,
|
||||||
IFeatureStrategySegment,
|
IFeatureStrategySegment,
|
||||||
|
ISegment,
|
||||||
ITag,
|
ITag,
|
||||||
} from '../types/model';
|
} from '../types/model';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
@ -37,6 +38,7 @@ export interface IExportData {
|
|||||||
contextFields: IContextFieldDto[];
|
contextFields: IContextFieldDto[];
|
||||||
featureStrategies: IFeatureStrategy[];
|
featureStrategies: IFeatureStrategy[];
|
||||||
featureEnvironments: IFeatureEnvironment[];
|
featureEnvironments: IFeatureEnvironment[];
|
||||||
|
segments: ISegment[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ExportImportService {
|
export default class ExportImportService {
|
||||||
@ -108,6 +110,7 @@ export default class ExportImportService {
|
|||||||
strategySegments,
|
strategySegments,
|
||||||
contextFields,
|
contextFields,
|
||||||
featureTags,
|
featureTags,
|
||||||
|
segments,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
this.toggleStore.getAllByNames(query.features),
|
this.toggleStore.getAllByNames(query.features),
|
||||||
await this.featureEnvironmentStore.getAllByFeatures(
|
await this.featureEnvironmentStore.getAllByFeatures(
|
||||||
@ -121,6 +124,7 @@ export default class ExportImportService {
|
|||||||
this.segmentStore.getAllFeatureStrategySegments(),
|
this.segmentStore.getAllFeatureStrategySegments(),
|
||||||
this.contextFieldStore.getAll(),
|
this.contextFieldStore.getAll(),
|
||||||
this.featureTagStore.getAll(),
|
this.featureTagStore.getAll(),
|
||||||
|
this.segmentStore.getAll(),
|
||||||
]);
|
]);
|
||||||
this.addSegmentsToStrategies(featureStrategies, strategySegments);
|
this.addSegmentsToStrategies(featureStrategies, strategySegments);
|
||||||
const filteredContextFields = contextFields.filter((field) =>
|
const filteredContextFields = contextFields.filter((field) =>
|
||||||
@ -130,12 +134,18 @@ export default class ExportImportService {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
const filteredSegments = segments.filter((segment) =>
|
||||||
|
featureStrategies.some((strategy) =>
|
||||||
|
strategy.segments.includes(segment.id),
|
||||||
|
),
|
||||||
|
);
|
||||||
const result = {
|
const result = {
|
||||||
features,
|
features,
|
||||||
featureStrategies,
|
featureStrategies,
|
||||||
featureEnvironments,
|
featureEnvironments,
|
||||||
contextFields: filteredContextFields,
|
contextFields: filteredContextFields,
|
||||||
featureTags,
|
featureTags,
|
||||||
|
segments: filteredSegments,
|
||||||
};
|
};
|
||||||
await this.eventStore.store({
|
await this.eventStore.store({
|
||||||
type: FEATURES_EXPORTED,
|
type: FEATURES_EXPORTED,
|
||||||
|
@ -134,8 +134,9 @@ afterAll(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('exports features', async () => {
|
test('exports features', async () => {
|
||||||
|
const segmentName = 'my-segment';
|
||||||
await createProject('default', 'default');
|
await createProject('default', 'default');
|
||||||
const segment = await createSegment({ name: 'S3', constraints: [] });
|
const segment = await createSegment({ name: segmentName, constraints: [] });
|
||||||
const strategy = {
|
const strategy = {
|
||||||
name: 'default',
|
name: 'default',
|
||||||
parameters: { rollout: '100', stickiness: 'default' },
|
parameters: { rollout: '100', stickiness: 'default' },
|
||||||
@ -187,6 +188,11 @@ test('exports features', async () => {
|
|||||||
variants: [],
|
variants: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
segments: [
|
||||||
|
{
|
||||||
|
name: segmentName,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -366,6 +372,7 @@ test('import features to existing project and environment', async () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
contextFields: [],
|
contextFields: [],
|
||||||
|
segments: [],
|
||||||
},
|
},
|
||||||
project: project,
|
project: project,
|
||||||
environment: environment,
|
environment: environment,
|
||||||
|
@ -1090,6 +1090,12 @@ exports[`should serve the OpenAPI spec 1`] = `
|
|||||||
},
|
},
|
||||||
"type": "array",
|
"type": "array",
|
||||||
},
|
},
|
||||||
|
"segments": {
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/segmentSchema",
|
||||||
|
},
|
||||||
|
"type": "array",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"features",
|
"features",
|
||||||
|
Loading…
Reference in New Issue
Block a user