Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(root): Replace shortid with nanoid #7720

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open

Conversation

SokratisVidros
Copy link
Contributor

What changed? Why was the change needed?

Shortid is deprecated and marked as unsafe. https://www.npmjs.com/package/shortid

See also https://github.com/novuhq/packages-enterprise/pull/267

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit ad585e6
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/67be079a57786b0008d46671
😎 Deploy Preview https://deploy-preview-7720.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

pkg-pr-new bot commented Feb 14, 2025

Open in Stackblitz

npm i https://pkg.pr.new/novuhq/novu/@novu/providers@7720

commit: a6472cd

@@ -149,7 +149,7 @@ export class CreateIntegration {
const defaultName =
providers.find((provider) => provider.id === command.providerId)?.displayName ?? providerIdCapitalized;
const name = command.name ?? defaultName;
const identifier = command.identifier ?? `${slugify(name)}-${shortid.generate()}`;
const identifier = command.identifier ?? `${slugify(name)}-${nanoid()}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need a longer id here as the default length is 4.

Copy link

netlify bot commented Feb 14, 2025

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit a6472cd
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/67cb173e1768e100085a9705
😎 Deploy Preview https://deploy-preview-7720.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -94,7 +94,6 @@
"rrule": "^2.7.2",
"rxjs": "7.8.1",
"sanitize-html": "^2.4.0",
"shortid": "^2.2.16",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@@ -62,7 +62,7 @@ export class IntegrationService {
channel,
credentials: {},
active,
identifier: `${slugify(name)}-${shortid.generate()}`,
identifier: `${slugify(name)}-${nanoid()}`,
Copy link
Contributor

@djabarovgeorge djabarovgeorge Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
identifier: `${slugify(name)}-${nanoid()}`,
identifier: `${slugify(name)}-${shortId()}`,

Copy link
Contributor

@djabarovgeorge djabarovgeorge Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please reuse the short Id from application-generic, so we will have the same alphabet even in tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferably will be to create eslint to prevent imports from nanoid

@@ -149,7 +149,7 @@ export class CreateIntegration {
const defaultName =
providers.find((provider) => provider.id === command.providerId)?.displayName ?? providerIdCapitalized;
const name = command.name ?? defaultName;
const identifier = command.identifier ?? `${slugify(name)}-${shortid.generate()}`;
const identifier = command.identifier ?? `${slugify(name)}-${nanoid()}`;
Copy link
Contributor

@djabarovgeorge djabarovgeorge Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const identifier = command.identifier ?? `${slugify(name)}-${nanoid()}`;
const identifier = command.identifier ?? `${slugify(name)}-${shortId()}`;

the default is length of 21
FYI for the future workflow and steps short id we had length of 6 #7029

regardless please use shortId from libs/application-generic/src/utils/generate-id.ts so we will have the same alphabet on our identifiers.

Copy link
Contributor

@djabarovgeorge djabarovgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, we just need to update the last place to use the internal shortId func

@SokratisVidros
Copy link
Contributor Author

@djabarovgeorge All comments have been addressed. Please take another look.

@@ -149,7 +149,7 @@ export class CreateIntegration {
const defaultName =
providers.find((provider) => provider.id === command.providerId)?.displayName ?? providerIdCapitalized;
const name = command.name ?? defaultName;
const identifier = command.identifier ?? `${slugify(name)}-${shortid.generate()}`;
const identifier = command.identifier ?? `${slugify(name)}-${shortId()}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before, we used shortId, which generated ids 7+ characters long

do we want to increase the length here as well?
reasons:

  1. to align with old ids.
  2. for future multi-tenancy support, which may require a larger identifier.

Copy link
Contributor

@djabarovgeorge djabarovgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, please check the last 2 comments that left.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants