Skip to content

Commit afcfdf8

Browse files
authored
Merge pull request #2555 from contentstack/chore/DX-6926
Chore/dx 6926
2 parents b061cd5 + 80ceb82 commit afcfdf8

6 files changed

Lines changed: 52 additions & 14 deletions

File tree

packages/contentstack-utilities/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"traverse": "^0.6.11",
5454
"tty-table": "^4.2.3",
5555
"unique-string": "^2.0.0",
56+
"short-uuid": "^6.0.0",
5657
"uuid": "^14.0.0",
5758
"winston": "^3.19.0",
5859
"xdg-basedir": "^4.0.0"

packages/contentstack-utilities/src/helpers.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { checkSync } from 'recheck';
22
import traverse from 'traverse';
3+
import { v4 as uuidV4 } from 'uuid';
4+
import { generate as shortUuidGenerate } from 'short-uuid';
35
import authHandler from './auth-handler';
46
import { ContentstackClient, HttpClient, cliux, configHandler } from '.';
57
import { hasProxy, getProxyUrl } from './proxy-helper';
@@ -278,6 +280,14 @@ export function getAuthenticationMethod(): string {
278280
* @param authenticationMethod - Optional authentication method
279281
* @returns Context object with all session-level metadata
280282
*/
283+
export function generateUid(): string {
284+
return uuidV4();
285+
}
286+
287+
export function generateShortUid(): string {
288+
return shortUuidGenerate();
289+
}
290+
281291
export function createLogContext(
282292
commandId: string,
283293
apiKey: string,

packages/contentstack-utilities/test/unit/helper.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cliux, validatePath, getBranchFromAlias } from '../../lib';
1+
import { cliux, validatePath, getBranchFromAlias, generateUid, generateShortUid } from '../../lib';
22
import { expect } from 'chai';
33
import { fancy } from 'fancy-test';
44

@@ -246,3 +246,32 @@ describe('Testing the getBranchFromAlias function', () => {
246246
});
247247
});
248248
});
249+
250+
describe('generateUid', () => {
251+
it('should return a string', () => {
252+
expect(generateUid()).to.be.a('string');
253+
});
254+
255+
it('should return a valid UUID v4 format', () => {
256+
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
257+
expect(generateUid()).to.match(uuidV4Regex);
258+
});
259+
260+
it('should return a unique value on each call', () => {
261+
expect(generateUid()).to.not.equal(generateUid());
262+
});
263+
});
264+
265+
describe('generateShortUid', () => {
266+
it('should return a string', () => {
267+
expect(generateShortUid()).to.be.a('string');
268+
});
269+
270+
it('should return a non-empty string', () => {
271+
expect(generateShortUid().length).to.be.greaterThan(0);
272+
});
273+
274+
it('should return a unique value on each call', () => {
275+
expect(generateShortUid()).to.not.equal(generateShortUid());
276+
});
277+
});

packages/contentstack/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
"@oclif/plugin-plugins": "^5.4.54",
4444
"figlet": "1.8.1",
4545
"node-machine-id": "^1.1.12",
46-
"semver": "^7.7.2",
47-
"short-uuid": "^6.0.0"
46+
"semver": "^7.7.2"
4847
},
4948
"overrides": {
5049
"@oclif/core": {

packages/contentstack/src/utils/context-handler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as shortUUID from 'short-uuid';
21
import * as path from 'path';
3-
import { configHandler, pathValidator, sanitizePath } from '@contentstack/cli-utilities';
2+
import { configHandler, pathValidator, sanitizePath, generateShortUid } from '@contentstack/cli-utilities';
43
import { machineIdSync } from 'node-machine-id';
54

65
export default class CsdxContext {
@@ -33,7 +32,7 @@ export default class CsdxContext {
3332
configHandler.set('clientId', this.clientId);
3433
}
3534
analyticsInfo.push(this.clientId);
36-
const sessionId = shortUUID.generate();
35+
const sessionId = generateShortUid();
3736
configHandler.set('sessionId', sessionId);
3837
this.sessionId = sessionId;
3938
analyticsInfo.push(this.sessionId);

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)