Skip to content

Commit

Permalink
Fix: make stickiness accept any string (#3408)
Browse files Browse the repository at this point in the history
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Changes the schema and api to accept any string for defaultStickiness
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
  • Loading branch information
andreas-unleash committed Mar 28, 2023
1 parent 96e327c commit 0d68feb
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 45 deletions.
Expand Up @@ -6,7 +6,7 @@ interface ICreatePayload {
name: string;
description: string;
mode: 'open' | 'protected';
defaultStickiness: 'default' | 'userId' | 'sessionId' | 'random';
defaultStickiness: string;
}

interface IAccessesPayload {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/db/project-store.ts
Expand Up @@ -3,7 +3,6 @@ import { Logger, LogProvider } from '../logger';

import NotFoundError from '../error/notfound-error';
import {
DefaultStickiness,
IEnvironment,
IFlagResolver,
IProject,
Expand Down Expand Up @@ -487,7 +486,7 @@ class ProjectStore implements IProjectStore {

async setProjectSettings(
projectId: string,
defaultStickiness: DefaultStickiness,
defaultStickiness: string,
mode: ProjectMode,
): Promise<void> {
await this.db(SETTINGS_TABLE)
Expand Down
1 change: 0 additions & 1 deletion src/lib/openapi/spec/health-overview-schema.ts
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/lib/openapi/spec/project-overview-schema.ts
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/lib/openapi/spec/project-schema.ts
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions src/lib/services/project-service.ts
Expand Up @@ -8,7 +8,6 @@ import { projectSchema } from './project-schema';
import NotFoundError from '../error/notfound-error';
import {
DEFAULT_PROJECT,
DefaultStickiness,
FEATURE_ENVIRONMENT_ENABLED,
FeatureToggle,
IAccountStore,
Expand Down Expand Up @@ -860,7 +859,7 @@ export default class ProjectService {

async setProjectSettings(
projectId: string,
defaultStickiness: DefaultStickiness,
defaultStickiness: string,
mode: ProjectMode,
): Promise<void> {
return this.store.setProjectSettings(
Expand Down
8 changes: 3 additions & 5 deletions src/lib/types/model.ts
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -190,7 +188,7 @@ export interface IProjectOverview {
stats?: IProjectStats;
mode: ProjectMode;

defaultStickiness: DefaultStickiness;
defaultStickiness: string;
}

export interface IProjectHealthReport extends IProjectOverview {
Expand Down Expand Up @@ -374,7 +372,7 @@ export interface IProject {
updatedAt?: Date;
changeRequestsEnabled?: boolean;
mode: ProjectMode;
defaultStickiness?: DefaultStickiness;
defaultStickiness?: string;
}

export interface ICustomRole {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/models/api-token.ts
Expand Up @@ -29,7 +29,7 @@ export interface IApiTokenCreate {
expiresAt?: Date;
}

export interface IApiToken extends IApiTokenCreate {
export interface IApiToken extends Omit<IApiTokenCreate, 'alias'> {
createdAt: Date;
seenAt?: Date;
environment: string;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/types/stores/project-store.ts
Expand Up @@ -3,7 +3,6 @@ import {
IProjectMembersCount,
} from '../../db/project-store';
import {
DefaultStickiness,
IEnvironment,
IProject,
IProjectWithCount,
Expand All @@ -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 {
Expand Down Expand Up @@ -101,7 +100,7 @@ export interface IProjectStore extends Store<IProject, string> {
getProjectSettings(projectId: string): Promise<IProjectSettings>;
setProjectSettings(
projectId: string,
defaultStickiness: DefaultStickiness,
defaultStickiness: string,
mode: ProjectMode,
): Promise<void>;
}
24 changes: 0 additions & 24 deletions src/test/e2e/api/openapi/__snapshots__/openapi.e2e.test.ts.snap
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down
5 changes: 2 additions & 3 deletions src/test/fixtures/fake-project-store.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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<void> {
Expand Down

0 comments on commit 0d68feb

Please sign in to comment.