Skip to content

Commit 06cc87b

Browse files
chore: remove uuid from the backend (#10807)
Backend only of: #10806 ## About the changes This PR drops the uuid package from node modules and replaces it with standard randomUUID usage that is available from 14.17 onwards, and we have a minimum requirement of node 20 at Unleash. [Node.js crypto](https://nodejs.org/api/crypto.html#cryptorandomuuidoptions) [Web crypto](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID) Co-authored-by: Anastasiia Hladina <[email protected]>
1 parent 4ff41fa commit 06cc87b

14 files changed

+90
-105
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129
"ts-toolbelt": "^9.6.0",
130130
"type-is": "^2.0.0",
131131
"ulidx": "^2.4.1",
132-
"unleash-client": "^6.8.0-beta.0",
133-
"uuid": "^11.0.0"
132+
"unleash-client": "^6.8.0-beta.0"
134133
},
135134
"devDependencies": {
136135
"@apidevtools/swagger-parser": "10.1.1",
@@ -161,7 +160,6 @@
161160
"@types/stoppable": "1.1.3",
162161
"@types/supertest": "6.0.3",
163162
"@types/type-is": "1.6.7",
164-
"@types/uuid": "9.0.8",
165163
"@vitest/coverage-v8": "^3.1.3",
166164
"@vitest/ui": "^3.1.3",
167165
"concurrently": "^9.0.0",

src/lib/db/feature-environment-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import metricsHelper from '../util/metrics-helper.js';
88
import { DB_TIME } from '../metric-events.js';
99
import type { IFeatureEnvironment, IVariant } from '../types/model.js';
1010
import NotFoundError from '../error/notfound-error.js';
11-
import { v4 as uuidv4 } from 'uuid';
1211
import type { Db } from './db.js';
1312
import type { IUnleashConfig } from '../types/index.js';
13+
import { randomId } from '../util/index.js';
1414

1515
const T = {
1616
featureEnvs: 'feature_environments',
@@ -495,7 +495,7 @@ export class FeatureEnvironmentStore implements IFeatureEnvironmentStore {
495495
const clonedStrategyRows = sourceFeatureStrategies.map(
496496
(featureStrategy) => ({
497497
...featureStrategy,
498-
id: uuidv4(),
498+
id: randomId(),
499499
environment: destinationEnvironment,
500500
parameters: JSON.stringify(featureStrategy.parameters),
501501
constraints: JSON.stringify(featureStrategy.constraints),

src/lib/error/unleash-error.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { v4 as uuidV4 } from 'uuid';
21
import type { FromSchema } from 'json-schema-to-ts';
2+
import { randomId } from '../util/random-id.js';
33

44
export const UnleashApiErrorTypes = [
55
'ContentTypeError',
@@ -48,7 +48,7 @@ export abstract class UnleashError extends Error {
4848

4949
constructor(message: string, name?: string) {
5050
super();
51-
this.id = uuidV4();
51+
this.id = randomId();
5252
this.name = name || this.constructor.name;
5353
super.message = message;
5454
}

src/lib/features/dependent-features/dependent.features.e2e.test.ts

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { v4 as uuidv4 } from 'uuid';
21
import dbInit, {
32
type ITestDb,
43
} from '../../../test/e2e/helpers/database-init.js';
@@ -13,7 +12,7 @@ import {
1312
FEATURE_DEPENDENCY_ADDED,
1413
FEATURE_DEPENDENCY_REMOVED,
1514
} from '../../events/index.js';
16-
import { DEFAULT_ENV } from '../../util/index.js';
15+
import { DEFAULT_ENV, randomId } from '../../util/index.js';
1716
import type { IEventStore } from '../../server-impl.js';
1817

1918
let app: IUnleashTest;
@@ -169,9 +168,9 @@ const checkDependenciesExist = async (expectedCode = 200) => {
169168
};
170169

171170
test('should add and delete feature dependencies', async () => {
172-
const parent = uuidv4();
173-
const child = uuidv4();
174-
const child2 = uuidv4();
171+
const parent = randomId();
172+
const child = randomId();
173+
const child2 = randomId();
175174
await app.createFeature(parent);
176175
await app.createFeature(child);
177176
await app.createFeature(child2);
@@ -209,10 +208,10 @@ test('should add and delete feature dependencies', async () => {
209208
});
210209

211210
test('should sort potential parent features alphabetically', async () => {
212-
const parent1 = `a${uuidv4()}`;
213-
const parent2 = `c${uuidv4()}`;
214-
const parent3 = `b${uuidv4()}`;
215-
const child = uuidv4();
211+
const parent1 = `a${randomId()}`;
212+
const parent2 = `c${randomId()}`;
213+
const parent3 = `b${randomId()}`;
214+
const child = randomId();
216215
await app.createFeature(parent1);
217216
await app.createFeature(parent2);
218217
await app.createFeature(parent3);
@@ -223,7 +222,7 @@ test('should sort potential parent features alphabetically', async () => {
223222
});
224223

225224
test('should sort potential parent variants', async () => {
226-
const parent = uuidv4();
225+
const parent = randomId();
227226
await app.createFeature(parent);
228227
await addFeatureEnvironmentVariant(parent, 'e');
229228
await addStrategyVariants(parent, ['c', 'a', 'd']);
@@ -235,9 +234,9 @@ test('should sort potential parent variants', async () => {
235234
});
236235

237236
test('should not allow to add grandparent', async () => {
238-
const grandparent = uuidv4();
239-
const parent = uuidv4();
240-
const child = uuidv4();
237+
const grandparent = randomId();
238+
const parent = randomId();
239+
const child = randomId();
241240
await app.createFeature(grandparent);
242241
await app.createFeature(parent);
243242
await app.createFeature(child);
@@ -255,9 +254,9 @@ test('should not allow to add grandparent', async () => {
255254
});
256255

257256
test('should not allow to add grandchild', async () => {
258-
const grandparent = uuidv4();
259-
const parent = uuidv4();
260-
const child = uuidv4();
257+
const grandparent = randomId();
258+
const parent = randomId();
259+
const child = randomId();
261260
await app.createFeature(grandparent);
262261
await app.createFeature(parent);
263262
await app.createFeature(child);
@@ -276,8 +275,8 @@ test('should not allow to add grandchild', async () => {
276275
});
277276

278277
test('should not allow to add non-existent parent dependency', async () => {
279-
const parent = uuidv4();
280-
const child = uuidv4();
278+
const parent = randomId();
279+
const child = randomId();
281280
await app.createFeature(child);
282281

283282
await addFeatureDependency(
@@ -290,8 +289,8 @@ test('should not allow to add non-existent parent dependency', async () => {
290289
});
291290

292291
test('should not allow to add archived parent dependency', async () => {
293-
const parent = uuidv4();
294-
const child = uuidv4();
292+
const parent = randomId();
293+
const child = randomId();
295294
await app.createFeature(child);
296295
await app.createFeature(parent);
297296
await app.archiveFeature(parent);
@@ -306,8 +305,8 @@ test('should not allow to add archived parent dependency', async () => {
306305
});
307306

308307
test('should check if any dependencies exist', async () => {
309-
const parent = uuidv4();
310-
const child = uuidv4();
308+
const parent = randomId();
309+
const child = randomId();
311310
await app.createFeature(child);
312311
await app.createFeature(parent);
313312

@@ -323,7 +322,7 @@ test('should check if any dependencies exist', async () => {
323322
});
324323

325324
test('should not allow to add dependency to self', async () => {
326-
const parent = uuidv4();
325+
const parent = randomId();
327326
await app.createFeature(parent);
328327

329328
await addFeatureDependency(
@@ -336,8 +335,8 @@ test('should not allow to add dependency to self', async () => {
336335
});
337336

338337
test('should not allow to add dependency to feature from another project', async () => {
339-
const child = uuidv4();
340-
const parent = uuidv4();
338+
const child = randomId();
339+
const parent = randomId();
341340
await app.createFeature(parent);
342341
await createProject('another-project');
343342
await app.createFeature(child, 'another-project');
@@ -351,8 +350,8 @@ test('should not allow to add dependency to feature from another project', async
351350
);
352351
});
353352
test('should create feature-dependency-removed when archiving and has dependency', async () => {
354-
const child = uuidv4();
355-
const parent = uuidv4();
353+
const child = randomId();
354+
const parent = randomId();
356355
await app.createFeature(parent);
357356
await app.createFeature(child);
358357

@@ -369,8 +368,8 @@ test('should create feature-dependency-removed when archiving and has dependency
369368
});
370369

371370
test('should not create feature-dependency-removed when archiving and no dependency', async () => {
372-
const child = uuidv4();
373-
const parent = uuidv4();
371+
const child = randomId();
372+
const parent = randomId();
374373
await app.createFeature(parent);
375374
await app.createFeature(child);
376375

src/lib/features/feature-toggle/feature-toggle-strategies-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Knex } from 'knex';
22
import type EventEmitter from 'events';
3-
import { v4 as uuidv4 } from 'uuid';
43
import metricsHelper from '../../util/metrics-helper.js';
54
import { DB_TIME } from '../../metric-events.js';
65
import type { Logger, LogProvider } from '../../logger.js';
@@ -24,6 +23,7 @@ import {
2423
ensureStringValue,
2524
generateImageUrl,
2625
mapValues,
26+
randomId,
2727
} from '../../util/index.js';
2828
import type { IFeatureProjectUserParams } from './feature-toggle-controller.js';
2929
import type { Db } from '../../db/db.js';
@@ -238,7 +238,7 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
238238
strategyConfig.environment,
239239
));
240240
const strategyRow = mapInput({
241-
id: uuidv4(),
241+
id: randomId(),
242242
...strategyConfig,
243243
sortOrder,
244244
});

0 commit comments

Comments
 (0)