mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(core,console): replace deduplicate logic with deduplicate
util (#2600)
This commit is contained in:
parent
a00782de29
commit
dac1f5cb49
6 changed files with 23 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
import type { LanguageTag } from '@logto/language-kit';
|
||||
import { builtInLanguages as builtInUiLanguages } from '@logto/phrases-ui';
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
|
@ -17,12 +18,10 @@ const useUiLanguages = () => {
|
|||
|
||||
const languages = useMemo(
|
||||
() =>
|
||||
[
|
||||
...new Set([
|
||||
...builtInUiLanguages,
|
||||
...(customPhraseList?.map(({ languageTag }) => languageTag) ?? []),
|
||||
]),
|
||||
]
|
||||
deduplicate([
|
||||
...builtInUiLanguages,
|
||||
...(customPhraseList?.map(({ languageTag }) => languageTag) ?? []),
|
||||
])
|
||||
.slice()
|
||||
.sort(),
|
||||
[customPhraseList]
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import type { Application, SnakeCaseOidcConfig } from '@logto/schemas';
|
||||
import { ApplicationType, UserRole } from '@logto/schemas';
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
|
@ -61,7 +62,7 @@ const AdvancedSettings = ({ applicationType, oidcConfig }: Props) => {
|
|||
checked={value.includes(UserRole.Admin)}
|
||||
onChange={({ currentTarget: { checked } }) => {
|
||||
if (checked) {
|
||||
onChange([...new Set(value.concat(UserRole.Admin))]);
|
||||
onChange(deduplicate(value.concat(UserRole.Admin)));
|
||||
} else {
|
||||
onChange(value.filter((value) => value !== UserRole.Admin));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import fs from 'fs/promises';
|
||||
import https from 'https';
|
||||
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import chalk from 'chalk';
|
||||
import type Koa from 'koa';
|
||||
import compose from 'koa-compose';
|
||||
|
@ -25,7 +26,7 @@ import initRouter from '#src/routes/init.js';
|
|||
const logListening = () => {
|
||||
const { localhostUrl, endpoint } = envSet.values;
|
||||
|
||||
for (const url of new Set([localhostUrl, endpoint])) {
|
||||
for (const url of deduplicate([localhostUrl, endpoint])) {
|
||||
console.log(chalk.bold(chalk.green(`App is running at ${url}`)));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
adminConsoleSignInExperience,
|
||||
demoAppApplicationId,
|
||||
} from '@logto/schemas/lib/seeds/index.js';
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import i18next from 'i18next';
|
||||
|
||||
import { getLogtoConnectors } from '#src/connectors/index.js';
|
||||
|
@ -50,7 +51,7 @@ export const validateTermsOfUse = (termsOfUse: TermsOfUse) => {
|
|||
|
||||
export const removeUnavailableSocialConnectorTargets = async () => {
|
||||
const connectors = await getLogtoConnectors();
|
||||
const availableSocialConnectorTargets = new Set(
|
||||
const availableSocialConnectorTargets = deduplicate(
|
||||
connectors
|
||||
.filter(({ type }) => type === ConnectorType.Social)
|
||||
.map(({ metadata: { target } }) => target)
|
||||
|
@ -59,7 +60,7 @@ export const removeUnavailableSocialConnectorTargets = async () => {
|
|||
const { socialSignInConnectorTargets } = await findDefaultSignInExperience();
|
||||
await updateDefaultSignInExperience({
|
||||
socialSignInConnectorTargets: socialSignInConnectorTargets.filter((target) =>
|
||||
availableSocialConnectorTargets.has(target)
|
||||
availableSocialConnectorTargets.includes(target)
|
||||
),
|
||||
});
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ import type { User, CreateUser } from '@logto/schemas';
|
|||
import { Users, UsersPasswordEncryptionMethod } from '@logto/schemas';
|
||||
import { buildIdGenerator } from '@logto/shared';
|
||||
import type { Nullable } from '@silverhand/essentials';
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import { argon2Verify } from 'hash-wasm';
|
||||
import pRetry from 'p-retry';
|
||||
|
||||
|
@ -66,9 +67,9 @@ const insertUserQuery = buildInsertInto<CreateUser, User>(Users, {
|
|||
// Temp solution since Hasura requires a role to proceed authn.
|
||||
// The source of default roles should be guarded and moved to database once we implement RBAC.
|
||||
export const insertUser: typeof insertUserQuery = async ({ roleNames, ...rest }) => {
|
||||
const computedRoleNames = [
|
||||
...new Set((roleNames ?? []).concat(envSet.values.userDefaultRoleNames)),
|
||||
];
|
||||
const computedRoleNames = deduplicate(
|
||||
(roleNames ?? []).concat(envSet.values.userDefaultRoleNames)
|
||||
);
|
||||
|
||||
if (computedRoleNames.length > 0) {
|
||||
const existingRoles = await findRolesByRoleNames(computedRoleNames);
|
||||
|
|
|
@ -2,6 +2,7 @@ import type { CreateApplication, OidcClientMetadata } from '@logto/schemas';
|
|||
import { ApplicationType } from '@logto/schemas';
|
||||
import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js';
|
||||
import { tryThat } from '@logto/shared';
|
||||
import { deduplicate } from '@silverhand/essentials';
|
||||
import { addSeconds } from 'date-fns';
|
||||
import type { AdapterFactory, AllClientMetadata } from 'oidc-provider';
|
||||
import { errors } from 'oidc-provider';
|
||||
|
@ -23,9 +24,10 @@ import { getConstantClientMetadata } from './utils.js';
|
|||
|
||||
const buildAdminConsoleClientMetadata = (): AllClientMetadata => {
|
||||
const { localhostUrl, adminConsoleUrl } = envSet.values;
|
||||
const urls = [
|
||||
...new Set([appendPath(localhostUrl, '/console').toString(), adminConsoleUrl.toString()]),
|
||||
];
|
||||
const urls = deduplicate([
|
||||
appendPath(localhostUrl, '/console').toString(),
|
||||
adminConsoleUrl.toString(),
|
||||
]);
|
||||
|
||||
return {
|
||||
...getConstantClientMetadata(ApplicationType.SPA),
|
||||
|
@ -46,8 +48,8 @@ const buildDemoAppUris = (
|
|||
];
|
||||
|
||||
const data = {
|
||||
redirectUris: [...new Set([...urls, ...oidcClientMetadata.redirectUris])],
|
||||
postLogoutRedirectUris: [...new Set([...urls, ...oidcClientMetadata.postLogoutRedirectUris])],
|
||||
redirectUris: deduplicate([...urls, ...oidcClientMetadata.redirectUris]),
|
||||
postLogoutRedirectUris: deduplicate([...urls, ...oidcClientMetadata.postLogoutRedirectUris]),
|
||||
};
|
||||
|
||||
return data;
|
||||
|
|
Loading…
Reference in a new issue