Skip to content

Commit

Permalink
[Gitar] Updating TypeScript files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitar committed Aug 19, 2024
1 parent 662c7ab commit ef1499d
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 109 deletions.
1 change: 0 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ exports[`should create default config 1`] = `
"experiments": {
"addonUsageMetrics": false,
"adminTokenKillSwitch": false,
"anonymiseEventLog": false,
"anonymizeProjectOwners": false,
"archiveProjects": false,
"automatedActions": false,
Expand Down
8 changes: 1 addition & 7 deletions src/lib/features/events/event-search-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import { normalizeQueryParams } from '../../features/feature-search/search-utils
import Controller from '../../routes/controller';
import type { IAuthRequest } from '../../server-impl';
import type { IEvent } from '../../types';
import { anonymiseKeys, extractUserIdFromUser } from '../../util';

const ANON_KEYS = ['email', 'username', 'createdBy'];
const version = 1 as const;
import { extractUserIdFromUser } from '../../util';
export default class EventSearchController extends Controller {
private eventService: EventService;

Expand Down Expand Up @@ -97,9 +94,6 @@ export default class EventSearchController extends Controller {
}

maybeAnonymiseEvents(events: IEvent[]): IEvent[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return anonymiseKeys(events, ANON_KEYS);
}
return events;
}
}
10 changes: 0 additions & 10 deletions src/lib/features/feature-search/feature-search-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
featureSearchQueryParameters,
} from '../../openapi/spec/feature-search-query-parameters';
import { normalizeQueryParams } from './search-utils';
import { anonymise } from '../../util';

type FeatureSearchServices = Pick<
IUnleashServices,
Expand Down Expand Up @@ -75,15 +74,6 @@ export default class FeatureSearchController extends Controller {
maybeAnonymise(
features: IFeatureSearchOverview[],
): IFeatureSearchOverview[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return features.map((feature) => ({
...feature,
createdBy: {
...feature.createdBy,
name: anonymise(feature.createdBy.name),
},
}));
}
return features;
}

Expand Down
23 changes: 10 additions & 13 deletions src/lib/features/feature-search/feature.search.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
anonymiseEventLog: true,
},
},
},
Expand Down Expand Up @@ -211,24 +210,22 @@ test('should paginate with offset', async () => {
await app.createFeature('my_feature_c');
await app.createFeature('my_feature_d');

const { body: firstPage, headers: firstHeaders } =
await searchFeaturesWithOffset({
query: 'feature',
offset: '0',
limit: '2',
});
const { body: firstPage } = await searchFeaturesWithOffset({
query: 'feature',
offset: '0',
limit: '2',
});

expect(firstPage).toMatchObject({
features: [{ name: 'my_feature_a' }, { name: 'my_feature_b' }],
total: 4,
});

const { body: secondPage, headers: secondHeaders } =
await searchFeaturesWithOffset({
query: 'feature',
offset: '2',
limit: '2',
});
const { body: secondPage } = await searchFeaturesWithOffset({
query: 'feature',
offset: '2',
limit: '2',
});

expect(secondPage).toMatchObject({
features: [{ name: 'my_feature_c' }, { name: 'my_feature_d' }],
Expand Down
38 changes: 3 additions & 35 deletions src/lib/features/feature-toggle/feature-toggle-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import type {
UnleashTransaction,
} from '../../db/transaction';
import { BadDataError } from '../../error';
import { anonymise } from '../../util';
import { throwOnInvalidSchema } from '../../openapi/validate';

interface FeatureStrategyParams {
Expand Down Expand Up @@ -699,31 +698,6 @@ export default class ProjectFeaturesController extends Controller {
}

maybeAnonymise(feature: FeatureToggleView): FeatureToggleView {
if (
this.flagResolver.isEnabled('anonymiseEventLog') &&
feature.createdBy
) {
return {
...feature,
...(feature.collaborators
? {
collaborators: {
...feature.collaborators,
users: feature.collaborators.users.map(
(user) => ({
...user,
name: anonymise(user.name),
}),
),
},
}
: {}),
createdBy: {
...feature.createdBy,
name: anonymise(feature.createdBy?.name),
},
};
}
return feature;
}

Expand Down Expand Up @@ -754,7 +728,7 @@ export default class ProjectFeaturesController extends Controller {
res: Response<FeatureSchema>,
): Promise<void> {
const { projectId, featureName } = req.params;
const { createdAt, ...data } = req.body;
const { ...data } = req.body;
if (data.name && data.name !== featureName) {
throw new BadDataError('Cannot change name of feature flag');
}
Expand Down Expand Up @@ -842,7 +816,7 @@ export default class ProjectFeaturesController extends Controller {
res: Response<FeatureEnvironmentSchema>,
): Promise<void> {
const { environment, featureName, projectId } = req.params;
const { defaultStrategy, ...environmentInfo } =
const { ...environmentInfo } =
await this.featureService.getEnvironmentInfo(
projectId,
environment,
Expand All @@ -852,13 +826,7 @@ export default class ProjectFeaturesController extends Controller {
const result = {
...environmentInfo,
strategies: environmentInfo.strategies.map((strategy) => {
const {
strategyName,
projectId: project,
environment: environmentId,
createdAt,
...rest
} = strategy;
const { strategyName, ...rest } = strategy;
return { ...rest, name: strategyName };
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ beforeAll(async () => {
experimental: {
flags: {
strictSchemaValidation: true,
anonymiseEventLog: true,
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions src/lib/features/segment/admin-segment.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ const validateSegment = (
beforeAll(async () => {
const customOptions = {
experimental: {
flags: {
anonymiseEventLog: true,
},
flags: {},
},
};

Expand Down
18 changes: 4 additions & 14 deletions src/lib/features/segment/segment-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
type SegmentsSchema,
} from '../../openapi/spec/segments-schema';

import { anonymiseKeys, extractUserIdFromUser } from '../../util';
import { extractUserIdFromUser } from '../../util';
import { BadDataError } from '../../error';
import idNumberMiddleware from '../../middleware/id-number-middleware';

Expand Down Expand Up @@ -286,11 +286,7 @@ export class SegmentsController extends Controller {
const { strategyId } = req.params;
const segments = await this.segmentService.getByStrategy(strategyId);

const responseBody = this.flagResolver.isEnabled('anonymiseEventLog')
? {
segments: anonymiseKeys(segments, ['createdBy']),
}
: { segments };
const responseBody = { segments };

this.openApiService.respondWithValidation(
200,
Expand Down Expand Up @@ -427,11 +423,7 @@ export class SegmentsController extends Controller {
): Promise<void> {
const id = Number(req.params.id);
const segment = await this.segmentService.get(id);
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
res.json(anonymiseKeys(segment, ['createdBy']));
} else {
res.json(segment);
}
res.json(segment);
}

async createSegment(
Expand Down Expand Up @@ -459,9 +451,7 @@ export class SegmentsController extends Controller {
const segments = await this.segmentService.getAll();

const response = {
segments: this.flagResolver.isEnabled('anonymiseEventLog')
? anonymiseKeys(segments, ['createdBy'])
: segments,
segments: segments,
};

this.openApiService.respondWithValidation<SegmentsSchema>(
Expand Down
6 changes: 0 additions & 6 deletions src/lib/routes/admin-api/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type EventService from '../../features/events/event-service';
import { ADMIN, NONE } from '../../types/permissions';
import type { IEvent, IEventList } from '../../types/events';
import Controller from '../controller';
import { anonymiseKeys } from '../../util/anonymise';
import type { OpenApiService } from '../../services/openapi-service';
import { createResponseSchema } from '../../openapi/util/create-response-schema';
import {
Expand All @@ -26,8 +25,6 @@ import {
eventCreatorsSchema,
type ProjectFlagCreatorsSchema,
} from '../../openapi';

const ANON_KEYS = ['email', 'username', 'createdBy'];
const version = 1 as const;
export default class EventController extends Controller {
private eventService: EventService;
Expand Down Expand Up @@ -143,9 +140,6 @@ export default class EventController extends Controller {
}

maybeAnonymiseEvents(events: IEvent[]): IEvent[] {
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
return anonymiseKeys(events, ANON_KEYS);
}
return events;
}

Expand Down
6 changes: 2 additions & 4 deletions src/lib/routes/admin-api/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import {
ProjectUserRemovedEvent,
} from '../../types/events';
import { TEST_AUDIT_USER } from '../../types';

const TEST_USER_ID = -9999;
async function getSetup(anonymise: boolean = false) {
async function getSetup() {
const base = `/random${Math.round(Math.random() * 1000)}`;
const stores = createStores();
const config = createTestConfig({
server: { baseUriPath: base },
experimental: { flags: { anonymiseEventLog: anonymise } },
experimental: { flags: {} },
});
const services = createServices(stores, config);
const app = await getApp(config, stores, services);
Expand Down
10 changes: 2 additions & 8 deletions src/lib/routes/admin-api/user-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@ export default class UserAdminController extends Controller {
typeof q === 'string' && q.length > 1
? await this.userService.search(q)
: [];
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
users = this.anonymiseUsers(users);
}
this.openApiService.respondWithValidation(
200,
res,
Expand All @@ -474,9 +471,6 @@ export default class UserAdminController extends Controller {
accountType: u.accountType,
} as IUser;
});
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
users = this.anonymiseUsers(users);
}

const allGroups = await this.groupService.getAll();
const groups = allGroups.map((g) => {
Expand Down Expand Up @@ -565,7 +559,7 @@ export default class UserAdminController extends Controller {
>,
res: Response<CreateUserResponseSchema>,
): Promise<void> {
const { user, params, body } = req;
const { params, body } = req;
const { id } = params;
const { name, email, rootRole } = body;

Expand Down Expand Up @@ -596,7 +590,7 @@ export default class UserAdminController extends Controller {
}

async deleteUser(req: IAuthRequest, res: Response): Promise<void> {
const { user, params } = req;
const { params } = req;
const { id } = params;

await this.throwIfScimUser({ id: Number(id) });
Expand Down
2 changes: 0 additions & 2 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { getDefaultVariant } from 'unleash-client/lib/variant';

export type IFlagKey =
| 'accessLogs'
| 'anonymiseEventLog'
| 'encryptEmails'
| 'enableLicense'
| 'enableLicenseChecker'
Expand Down Expand Up @@ -72,7 +71,6 @@ export type IFlagKey =
export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

const flags: IFlags = {
anonymiseEventLog: false,
enableLicense: false,
enableLicenseChecker: false,
embedProxy: parseEnvVarBoolean(
Expand Down
3 changes: 0 additions & 3 deletions src/lib/users/inactive/inactive-users-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ export class InactiveUsersController extends Controller {
): Promise<void> {
this.logger.info('Hitting inactive users');
let inactiveUsers = await this.inactiveUsersService.getInactiveUsers();
if (this.flagResolver.isEnabled('anonymiseEventLog')) {
inactiveUsers = this.anonymiseUsers(inactiveUsers);
}
this.openApiService.respondWithValidation(
200,
res,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ process.nextTick(async () => {
flags: {
embedProxy: true,
embedProxyFrontend: true,
anonymiseEventLog: false,
responseTimeWithAppNameKillSwitch: false,
stripHeadersOnAPI: true,
celebrateUnleash: true,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/api/admin/user-admin.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ test('generates USER_UPDATED event', async () => {
test('Anonymises name, username and email fields if anonymiseEventLog flag is set', async () => {
const anonymisedApp = await setupAppWithCustomConfig(
stores,
{ experimental: { flags: { anonymiseEventLog: true } } },
{ experimental: { flags: {} } },
db.rawDatabase,
);
await anonymisedApp.request
Expand Down

0 comments on commit ef1499d

Please sign in to comment.