From 0d68febdf7437b4efd7754fd91026d6fc69229e7 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Tue, 28 Mar 2023 16:42:16 +0300 Subject: [PATCH] Fix: make stickiness accept any string (#3408) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the schema and api to accept any string for defaultStickiness ## About the changes Closes # ### Important files ## Discussion points --------- Signed-off-by: andreas-unleash --- .../actions/useProjectApi/useProjectApi.ts | 2 +- src/lib/db/project-store.ts | 3 +-- .../openapi/spec/health-overview-schema.ts | 1 - .../openapi/spec/project-overview-schema.ts | 1 - src/lib/openapi/spec/project-schema.ts | 1 - src/lib/services/project-service.ts | 3 +-- src/lib/types/model.ts | 8 +++---- src/lib/types/models/api-token.ts | 2 +- src/lib/types/stores/project-store.ts | 7 +++--- .../__snapshots__/openapi.e2e.test.ts.snap | 24 ------------------- src/test/fixtures/fake-project-store.ts | 5 ++-- 11 files changed, 12 insertions(+), 45 deletions(-) diff --git a/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts b/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts index 12063a895c..df7eb4edef 100644 --- a/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts +++ b/frontend/src/hooks/api/actions/useProjectApi/useProjectApi.ts @@ -6,7 +6,7 @@ interface ICreatePayload { name: string; description: string; mode: 'open' | 'protected'; - defaultStickiness: 'default' | 'userId' | 'sessionId' | 'random'; + defaultStickiness: string; } interface IAccessesPayload { diff --git a/src/lib/db/project-store.ts b/src/lib/db/project-store.ts index 78368b599c..82c558b595 100644 --- a/src/lib/db/project-store.ts +++ b/src/lib/db/project-store.ts @@ -3,7 +3,6 @@ import { Logger, LogProvider } from '../logger'; import NotFoundError from '../error/notfound-error'; import { - DefaultStickiness, IEnvironment, IFlagResolver, IProject, @@ -487,7 +486,7 @@ class ProjectStore implements IProjectStore { async setProjectSettings( projectId: string, - defaultStickiness: DefaultStickiness, + defaultStickiness: string, mode: ProjectMode, ): Promise { await this.db(SETTINGS_TABLE) diff --git a/src/lib/openapi/spec/health-overview-schema.ts b/src/lib/openapi/spec/health-overview-schema.ts index f0bbaebea2..df6069f1a5 100644 --- a/src/lib/openapi/spec/health-overview-schema.ts +++ b/src/lib/openapi/spec/health-overview-schema.ts @@ -27,7 +27,6 @@ export const healthOverviewSchema = { }, defaultStickiness: { type: 'string', - enum: ['default', 'userId', 'sessionId', 'random'], example: 'userId', description: 'A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy', diff --git a/src/lib/openapi/spec/project-overview-schema.ts b/src/lib/openapi/spec/project-overview-schema.ts index fc0b57f86e..310eb12a9c 100644 --- a/src/lib/openapi/spec/project-overview-schema.ts +++ b/src/lib/openapi/spec/project-overview-schema.ts @@ -38,7 +38,6 @@ export const projectOverviewSchema = { }, defaultStickiness: { type: 'string', - enum: ['default', 'userId', 'sessionId', 'random'], example: 'userId', description: 'A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy', diff --git a/src/lib/openapi/spec/project-schema.ts b/src/lib/openapi/spec/project-schema.ts index 12a667287d..ef7e41d7f6 100644 --- a/src/lib/openapi/spec/project-schema.ts +++ b/src/lib/openapi/spec/project-schema.ts @@ -64,7 +64,6 @@ export const projectSchema = { }, defaultStickiness: { type: 'string', - enum: ['default', 'userId', 'sessionId', 'random'], example: 'userId', description: 'A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy', diff --git a/src/lib/services/project-service.ts b/src/lib/services/project-service.ts index 4e3553540f..2fddcb4c0a 100644 --- a/src/lib/services/project-service.ts +++ b/src/lib/services/project-service.ts @@ -8,7 +8,6 @@ import { projectSchema } from './project-schema'; import NotFoundError from '../error/notfound-error'; import { DEFAULT_PROJECT, - DefaultStickiness, FEATURE_ENVIRONMENT_ENABLED, FeatureToggle, IAccountStore, @@ -860,7 +859,7 @@ export default class ProjectService { async setProjectSettings( projectId: string, - defaultStickiness: DefaultStickiness, + defaultStickiness: string, mode: ProjectMode, ): Promise { return this.store.setProjectSettings( diff --git a/src/lib/types/model.ts b/src/lib/types/model.ts index 3928317733..dd6a517f2b 100644 --- a/src/lib/types/model.ts +++ b/src/lib/types/model.ts @@ -2,7 +2,7 @@ import { ITagType } from './stores/tag-type-store'; import { LogProvider } from '../logger'; import { IRole } from './stores/access-store'; import { IUser } from './user'; -import { ALL_OPERATORS } from '../util/constants'; +import { ALL_OPERATORS } from '../util'; import { IProjectStats } from 'lib/services/project-service'; export type Operator = typeof ALL_OPERATORS[number]; @@ -175,8 +175,6 @@ export interface IFeatureOverview { export type ProjectMode = 'open' | 'protected'; -export type DefaultStickiness = 'default' | 'sessionId' | 'userId' | 'random'; - export interface IProjectOverview { name: string; description: string; @@ -190,7 +188,7 @@ export interface IProjectOverview { stats?: IProjectStats; mode: ProjectMode; - defaultStickiness: DefaultStickiness; + defaultStickiness: string; } export interface IProjectHealthReport extends IProjectOverview { @@ -374,7 +372,7 @@ export interface IProject { updatedAt?: Date; changeRequestsEnabled?: boolean; mode: ProjectMode; - defaultStickiness?: DefaultStickiness; + defaultStickiness?: string; } export interface ICustomRole { diff --git a/src/lib/types/models/api-token.ts b/src/lib/types/models/api-token.ts index 97d2a68372..ab10be83f7 100644 --- a/src/lib/types/models/api-token.ts +++ b/src/lib/types/models/api-token.ts @@ -29,7 +29,7 @@ export interface IApiTokenCreate { expiresAt?: Date; } -export interface IApiToken extends IApiTokenCreate { +export interface IApiToken extends Omit { createdAt: Date; seenAt?: Date; environment: string; diff --git a/src/lib/types/stores/project-store.ts b/src/lib/types/stores/project-store.ts index 921c9880de..66bd489540 100644 --- a/src/lib/types/stores/project-store.ts +++ b/src/lib/types/stores/project-store.ts @@ -3,7 +3,6 @@ import { IProjectMembersCount, } from '../../db/project-store'; import { - DefaultStickiness, IEnvironment, IProject, IProjectWithCount, @@ -22,12 +21,12 @@ export interface IProjectInsert { export interface IProjectSettings { mode: ProjectMode; - defaultStickiness: DefaultStickiness; + defaultStickiness: string; } export interface IProjectSettingsRow { project_mode: ProjectMode; - default_stickiness: DefaultStickiness; + default_stickiness: string; } export interface IProjectArchived { @@ -101,7 +100,7 @@ export interface IProjectStore extends Store { getProjectSettings(projectId: string): Promise; setProjectSettings( projectId: string, - defaultStickiness: DefaultStickiness, + defaultStickiness: string, mode: ProjectMode, ): Promise; } diff --git a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap index b7c204b360..27fd662d47 100644 --- a/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap +++ b/src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap @@ -1843,12 +1843,6 @@ exports[`should serve the OpenAPI spec 1`] = ` "properties": { "defaultStickiness": { "description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy", - "enum": [ - "default", - "userId", - "sessionId", - "random", - ], "example": "userId", "type": "string", }, @@ -1916,12 +1910,6 @@ exports[`should serve the OpenAPI spec 1`] = ` }, "defaultStickiness": { "description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy", - "enum": [ - "default", - "userId", - "sessionId", - "random", - ], "example": "userId", "type": "string", }, @@ -2781,12 +2769,6 @@ exports[`should serve the OpenAPI spec 1`] = ` "properties": { "defaultStickiness": { "description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy", - "enum": [ - "default", - "userId", - "sessionId", - "random", - ], "example": "userId", "type": "string", }, @@ -2874,12 +2856,6 @@ exports[`should serve the OpenAPI spec 1`] = ` }, "defaultStickiness": { "description": "A default stickiness for the project affecting the default stickiness value for variants and Gradual Rollout strategy", - "enum": [ - "default", - "userId", - "sessionId", - "random", - ], "example": "userId", "type": "string", }, diff --git a/src/test/fixtures/fake-project-store.ts b/src/test/fixtures/fake-project-store.ts index 06b2f18606..6f93de903b 100644 --- a/src/test/fixtures/fake-project-store.ts +++ b/src/test/fixtures/fake-project-store.ts @@ -5,12 +5,11 @@ import { IProjectStore, } from '../../lib/types/stores/project-store'; import { - DefaultStickiness, IEnvironment, IProject, IProjectWithCount, ProjectMode, -} from '../../lib/types/model'; +} from '../../lib/types'; import NotFoundError from '../../lib/error/notfound-error'; import { IEnvironmentProjectLink, @@ -174,7 +173,7 @@ export default class FakeProjectStore implements IProjectStore { // eslint-disable-next-line @typescript-eslint/no-unused-vars projectId: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - defaultStickiness: DefaultStickiness, + defaultStickiness: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars mode: ProjectMode, ): Promise {