mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
feat: store domain for links (#9931)
This commit is contained in:
parent
9ca44e6188
commit
28e5f39548
@ -167,6 +167,7 @@
|
||||
"serve-favicon": "^2.5.0",
|
||||
"slug": "^9.0.0",
|
||||
"stoppable": "^1.1.0",
|
||||
"tldts": "7.0.6",
|
||||
"ts-toolbelt": "^9.6.0",
|
||||
"type-is": "^1.6.18",
|
||||
"ulidx": "^2.4.1",
|
||||
|
@ -11,13 +11,18 @@ test('create, update and delete feature link', async () => {
|
||||
|
||||
const link = await featureLinkService.createLink(
|
||||
'default',
|
||||
{ featureName: 'feature', url: 'example.com', title: 'some title' },
|
||||
{
|
||||
featureName: 'feature',
|
||||
url: 'complex.example.com',
|
||||
title: 'some title',
|
||||
},
|
||||
{} as IAuditUser,
|
||||
);
|
||||
expect(link).toMatchObject({
|
||||
featureName: 'feature',
|
||||
url: 'https://example.com',
|
||||
url: 'https://complex.example.com',
|
||||
title: 'some title',
|
||||
domain: 'example',
|
||||
});
|
||||
|
||||
const newLink = await featureLinkService.updateLink(
|
||||
@ -33,6 +38,7 @@ test('create, update and delete feature link', async () => {
|
||||
featureName: 'feature',
|
||||
url: 'https://example1.com',
|
||||
title: 'new title',
|
||||
domain: 'example1',
|
||||
});
|
||||
|
||||
await featureLinkService.deleteLink(
|
||||
|
@ -13,6 +13,7 @@ import type {
|
||||
import type EventService from '../events/event-service';
|
||||
import { BadDataError, NotFoundError } from '../../error';
|
||||
import normalizeUrl from 'normalize-url';
|
||||
import { parse } from 'tldts';
|
||||
|
||||
interface IFeatureLinkStoreObj {
|
||||
featureLinkStore: IFeatureLinkStore;
|
||||
@ -47,14 +48,16 @@ export default class FeatureLinkService {
|
||||
|
||||
async createLink(
|
||||
projectId: string,
|
||||
newLink: Omit<IFeatureLink, 'id'>,
|
||||
newLink: Omit<IFeatureLink, 'id' | 'domain'>,
|
||||
auditUser: IAuditUser,
|
||||
): Promise<IFeatureLink> {
|
||||
const normalizedUrl = this.normalize(newLink.url);
|
||||
const { domainWithoutSuffix } = parse(normalizedUrl);
|
||||
|
||||
const link = await this.featureLinkStore.insert({
|
||||
...newLink,
|
||||
url: normalizedUrl,
|
||||
domain: domainWithoutSuffix,
|
||||
});
|
||||
|
||||
await this.eventService.storeEvent(
|
||||
@ -71,10 +74,11 @@ export default class FeatureLinkService {
|
||||
|
||||
async updateLink(
|
||||
{ projectId, linkId }: { projectId: string; linkId: string },
|
||||
updatedLink: Omit<IFeatureLink, 'id'>,
|
||||
updatedLink: Omit<IFeatureLink, 'id' | 'domain'>,
|
||||
auditUser: IAuditUser,
|
||||
): Promise<IFeatureLink> {
|
||||
const normalizedUrl = this.normalize(updatedLink.url);
|
||||
const { domainWithoutSuffix } = parse(normalizedUrl);
|
||||
|
||||
const preData = await this.featureLinkStore.get(linkId);
|
||||
|
||||
@ -85,6 +89,7 @@ export default class FeatureLinkService {
|
||||
const link = await this.featureLinkStore.update(linkId, {
|
||||
...updatedLink,
|
||||
url: normalizedUrl,
|
||||
domain: domainWithoutSuffix,
|
||||
});
|
||||
|
||||
await this.eventService.storeEvent(
|
||||
|
@ -5,6 +5,7 @@ export interface IFeatureLink {
|
||||
featureName: string;
|
||||
url: string;
|
||||
title?: string;
|
||||
domain: string | null;
|
||||
}
|
||||
|
||||
export interface IFeatureLinkStore extends Store<IFeatureLink, string> {
|
||||
|
19
yarn.lock
19
yarn.lock
@ -9061,6 +9061,24 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tldts-core@npm:^7.0.6":
|
||||
version: 7.0.6
|
||||
resolution: "tldts-core@npm:7.0.6"
|
||||
checksum: 10c0/32910f8098bdbb313e3d5ff1ef80cac51568c7682ab5de44d244edf7a08e02b1f7918677c8bf7d52c79f864d4b972bcec83b46e439d0a447f6049423394000c3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tldts@npm:7.0.6":
|
||||
version: 7.0.6
|
||||
resolution: "tldts@npm:7.0.6"
|
||||
dependencies:
|
||||
tldts-core: "npm:^7.0.6"
|
||||
bin:
|
||||
tldts: bin/cli.js
|
||||
checksum: 10c0/9c23a74c017a4cc73323543dc372fb00fc5ee3d4851cdebb4d9d65e7a959c386fc4e40c96574aed8f8c1214956d3777cb9438edf34538e2f1501be94ab1b98fb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tmpl@npm:1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "tmpl@npm:1.0.5"
|
||||
@ -9483,6 +9501,7 @@ __metadata:
|
||||
stoppable: "npm:^1.1.0"
|
||||
superagent: "npm:10.2.0"
|
||||
supertest: "npm:7.0.0"
|
||||
tldts: "npm:7.0.6"
|
||||
ts-node: "npm:10.9.2"
|
||||
ts-toolbelt: "npm:^9.6.0"
|
||||
tsc-watch: "npm:6.2.1"
|
||||
|
Loading…
Reference in New Issue
Block a user