diff --git a/.husky/pre-commit b/.husky/pre-commit index 058f96add..fe156c99e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,6 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -FORCE_COLOR=1 pnpm -r --filter "[HEAD]" precommit +# Keep concurrency 1 to avoid lint-staged issue +# Which may cause ALL your work LOST WITHOUT STASH +FORCE_COLOR=1 pnpm -r --workspace-concurrency 1 --filter "[HEAD]" precommit diff --git a/packages/console/src/components/ApplicationName/index.tsx b/packages/console/src/components/ApplicationName/index.tsx index 25f5c987b..bf345982d 100644 --- a/packages/console/src/components/ApplicationName/index.tsx +++ b/packages/console/src/components/ApplicationName/index.tsx @@ -14,7 +14,7 @@ type Props = { const ApplicationName = ({ applicationId, isLink = false }: Props) => { const isAdminConsole = applicationId === adminConsoleApplicationId; - const { data } = useSWR(!isAdminConsole && `/api/applications/${applicationId}`); + const { data } = useSWR(!isAdminConsole && `api/applications/${applicationId}`); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const name = (isAdminConsole ? <>Admin Console ({t('system_app')}) : data?.name) ?? '-'; diff --git a/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx b/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx index e685bfab3..f87cc0ce1 100644 --- a/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx +++ b/packages/console/src/components/AuditLogTable/components/ApplicationSelector/index.tsx @@ -12,7 +12,7 @@ type Props = { const ApplicationSelector = ({ value, onChange }: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data } = useSWR('/api/applications'); + const { data } = useSWR('api/applications'); const options = data?.map(({ id, name }) => ({ value: id, diff --git a/packages/console/src/components/AuditLogTable/index.tsx b/packages/console/src/components/AuditLogTable/index.tsx index a55d9f34b..c0c9c3608 100644 --- a/packages/console/src/components/AuditLogTable/index.tsx +++ b/packages/console/src/components/AuditLogTable/index.tsx @@ -34,7 +34,7 @@ const AuditLogTable = ({ userId, className }: Props) => { applicationId: '', }); - const url = buildUrl('/api/logs', { + const url = buildUrl('api/logs', { page: String(page), page_size: String(pageSize), ...conditional(event && { logType: event }), diff --git a/packages/console/src/components/RoleScopesTransfer/components/SourceScopesBox/index.tsx b/packages/console/src/components/RoleScopesTransfer/components/SourceScopesBox/index.tsx index 50354bc38..1172b0af5 100644 --- a/packages/console/src/components/RoleScopesTransfer/components/SourceScopesBox/index.tsx +++ b/packages/console/src/components/RoleScopesTransfer/components/SourceScopesBox/index.tsx @@ -29,10 +29,10 @@ const SourceScopesBox = ({ roleId, selectedScopes, onChange }: Props) => { const { data: allResources, error: fetchAllResourcesError } = useSWR< ResourceResponse[], RequestError - >('/api/resources?includeScopes=true'); + >('api/resources?includeScopes=true'); const { data: roleScopes, error: fetchRoleScopesError } = useSWR( - roleId && `/api/roles/${roleId}/scopes` + roleId && `api/roles/${roleId}/scopes` ); const isLoading = diff --git a/packages/console/src/components/RoleUsersTransfer/components/SourceUsersBox/index.tsx b/packages/console/src/components/RoleUsersTransfer/components/SourceUsersBox/index.tsx index 34ca951d6..271607441 100644 --- a/packages/console/src/components/RoleUsersTransfer/components/SourceUsersBox/index.tsx +++ b/packages/console/src/components/RoleUsersTransfer/components/SourceUsersBox/index.tsx @@ -33,7 +33,7 @@ const SourceUsersBox = ({ roleId, selectedUsers, onChange }: Props) => { const [keyword, setKeyword] = useState(''); const debounce = useDebounce(); - const url = buildUrl('/api/users', { + const url = buildUrl('api/users', { excludeRoleId: roleId, hideAdminUser: String(true), page: String(page), diff --git a/packages/console/src/components/UserName/index.tsx b/packages/console/src/components/UserName/index.tsx index 79b704aaf..a7722e384 100644 --- a/packages/console/src/components/UserName/index.tsx +++ b/packages/console/src/components/UserName/index.tsx @@ -14,7 +14,7 @@ type Props = { }; const UserName = ({ userId, isLink = false }: Props) => { - const { data, error } = useSWR(`/api/users/${userId}`); + const { data, error } = useSWR(`api/users/${userId}`); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const isLoading = !data && !error; diff --git a/packages/console/src/components/UserRolesTransfer/components/SourceRolesBox/index.tsx b/packages/console/src/components/UserRolesTransfer/components/SourceRolesBox/index.tsx index 8e2c81514..d43dd6a55 100644 --- a/packages/console/src/components/UserRolesTransfer/components/SourceRolesBox/index.tsx +++ b/packages/console/src/components/UserRolesTransfer/components/SourceRolesBox/index.tsx @@ -35,7 +35,7 @@ const SourceRolesBox = ({ userId, selectedRoles, onChange }: Props) => { const debounce = useDebounce(); - const url = buildUrl('/api/roles', { + const url = buildUrl('api/roles', { excludeUserId: userId, page: String(page), page_size: String(pageSize), diff --git a/packages/console/src/hooks/use-api.ts b/packages/console/src/hooks/use-api.ts index aeef5ab2d..ad33676c4 100644 --- a/packages/console/src/hooks/use-api.ts +++ b/packages/console/src/hooks/use-api.ts @@ -44,6 +44,7 @@ const useApi = ({ hideErrorToast }: Props = {}) => { const api = useMemo( () => ky.create({ + prefixUrl: window.location.origin, timeout: requestTimeout, hooks: { beforeError: hideErrorToast diff --git a/packages/console/src/hooks/use-configs.ts b/packages/console/src/hooks/use-configs.ts index 9d3df4d28..a03007a07 100644 --- a/packages/console/src/hooks/use-configs.ts +++ b/packages/console/src/hooks/use-configs.ts @@ -12,12 +12,12 @@ const useConfigs = () => { data: configs, error, mutate, - } = useSWR(shouldFetch && '/api/configs/admin-console'); + } = useSWR(shouldFetch && 'api/configs/admin-console'); const api = useApi(); const updateConfigs = async (json: Partial) => { const updatedConfigs = await api - .patch('/api/configs/admin-console', { + .patch('api/configs/admin-console', { json, }) .json(); diff --git a/packages/console/src/hooks/use-connector-groups.ts b/packages/console/src/hooks/use-connector-groups.ts index 1c0a51f44..7e021133d 100644 --- a/packages/console/src/hooks/use-connector-groups.ts +++ b/packages/console/src/hooks/use-connector-groups.ts @@ -7,7 +7,7 @@ import { getConnectorGroups } from '@/pages/Connectors/utils'; // Group connectors by target const useConnectorGroups = () => { - const { data, ...rest } = useSWR('/api/connectors'); + const { data, ...rest } = useSWR('api/connectors'); const groups = useMemo(() => { if (!data) { diff --git a/packages/console/src/hooks/use-connector-in-use.ts b/packages/console/src/hooks/use-connector-in-use.ts index 766f2655d..00c22bca6 100644 --- a/packages/console/src/hooks/use-connector-in-use.ts +++ b/packages/console/src/hooks/use-connector-in-use.ts @@ -6,7 +6,7 @@ import useSWR from 'swr'; import type { RequestError } from './use-api'; const useConnectorInUse = () => { - const { data } = useSWR('/api/sign-in-exp'); + const { data } = useSWR('api/sign-in-exp'); const isConnectorInUse = useCallback( (connector?: ConnectorResponse) => { diff --git a/packages/console/src/hooks/use-enabled-connector-types.ts b/packages/console/src/hooks/use-enabled-connector-types.ts index 19910ed64..c72e37b53 100644 --- a/packages/console/src/hooks/use-enabled-connector-types.ts +++ b/packages/console/src/hooks/use-enabled-connector-types.ts @@ -5,7 +5,7 @@ import useSWR from 'swr'; import type { RequestError } from './use-api'; const useEnabledConnectorTypes = () => { - const { data: connectors } = useSWR('/api/connectors'); + const { data: connectors } = useSWR('api/connectors'); const enabledConnectorTypes = useMemo( () => connectors?.map(({ type }) => type) ?? [], diff --git a/packages/console/src/hooks/use-ui-languages.ts b/packages/console/src/hooks/use-ui-languages.ts index 27d4ae30c..4f5b1234c 100644 --- a/packages/console/src/hooks/use-ui-languages.ts +++ b/packages/console/src/hooks/use-ui-languages.ts @@ -14,7 +14,7 @@ const useUiLanguages = () => { data: customPhraseList, error, mutate, - } = useSWR('/api/custom-phrases'); + } = useSWR('api/custom-phrases'); const languages = useMemo( () => @@ -31,7 +31,7 @@ const useUiLanguages = () => { const addLanguage = useCallback( async (languageTag: LanguageTag) => { - await api.put(`/api/custom-phrases/${languageTag}`, { json: {} }); + await api.put(`api/custom-phrases/${languageTag}`, { json: {} }); await mutate(); }, [api, mutate] diff --git a/packages/console/src/hooks/use-user-preferences.ts b/packages/console/src/hooks/use-user-preferences.ts index c2ab27d59..6d8fc14d0 100644 --- a/packages/console/src/hooks/use-user-preferences.ts +++ b/packages/console/src/hooks/use-user-preferences.ts @@ -36,7 +36,7 @@ const useUserPreferences = () => { const userId = useLogtoUserId(); const shouldFetch = isAuthenticated && !authError && userId; const { data, mutate, error } = useSWR( - shouldFetch && `/api/users/${userId}/custom-data` + shouldFetch && `api/users/${userId}/custom-data` ); const api = useApi(); @@ -62,7 +62,7 @@ const useUserPreferences = () => { } const updated = await api - .patch(`/api/users/${userId}/custom-data`, { + .patch(`api/users/${userId}/custom-data`, { json: { customData: { [key]: { diff --git a/packages/console/src/mdx-components/UriInputField/index.tsx b/packages/console/src/mdx-components/UriInputField/index.tsx index bb71ad9be..0367832d6 100644 --- a/packages/console/src/mdx-components/UriInputField/index.tsx +++ b/packages/console/src/mdx-components/UriInputField/index.tsx @@ -36,7 +36,7 @@ const UriInputField = ({ appId, name, title, isSingle = false }: Props) => { formState: { isSubmitting }, } = methods; - const { data, mutate } = useSWR(`/api/applications/${appId}`); + const { data, mutate } = useSWR(`api/applications/${appId}`); const ref = useRef(null); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); @@ -44,7 +44,7 @@ const UriInputField = ({ appId, name, title, isSingle = false }: Props) => { const onSubmit = async (value: string[]) => { const updatedApp = await api - .patch(`/api/applications/${appId}`, { + .patch(`api/applications/${appId}`, { json: { oidcClientMetadata: { [name]: value.filter(Boolean), diff --git a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/components/CreatePermissionModal/index.tsx b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/components/CreatePermissionModal/index.tsx index 891d452e8..4690a9080 100644 --- a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/components/CreatePermissionModal/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/components/CreatePermissionModal/index.tsx @@ -34,7 +34,7 @@ const CreatePermissionModal = ({ resourceId, onClose }: Props) => { } const createdScope = await api - .post(`/api/resources/${resourceId}/scopes`, { json: formData }) + .post(`api/resources/${resourceId}/scopes`, { json: formData }) .json(); onClose(createdScope); diff --git a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx index 988931eda..b0ffe9b0a 100644 --- a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx @@ -34,7 +34,7 @@ const ApiResourcePermissions = () => { const { data, error, mutate } = useSWR<[ScopeResponse[], number], RequestError>( resourceId && - buildUrl(`/api/resources/${resourceId}/scopes`, { + buildUrl(`api/resources/${resourceId}/scopes`, { page: String(page), page_size: String(pageSize), ...conditional(keyword && { search: formatSearchKeyword(keyword) }), @@ -57,7 +57,7 @@ const ApiResourcePermissions = () => { setIsDeleting(true); try { - await api.delete(`/api/resources/${resourceId}/scopes/${scopeToBeDeleted.id}`); + await api.delete(`api/resources/${resourceId}/scopes/${scopeToBeDeleted.id}`); toast.success(t('api_resource_details.permission.deleted', { name: scopeToBeDeleted.name })); await mutate(); setScopeToBeDeleted(undefined); diff --git a/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx b/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx index 8e23ead34..c1a34ceae 100644 --- a/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/ApiResourceSettings/index.tsx @@ -38,7 +38,7 @@ const ApiResourceSettings = () => { } const updatedApiResource = await api - .patch(`/api/resources/${resource.id}`, { json: formData }) + .patch(`api/resources/${resource.id}`, { json: formData }) .json(); reset(updatedApiResource); onResourceUpdated(updatedApiResource); diff --git a/packages/console/src/pages/ApiResourceDetails/index.tsx b/packages/console/src/pages/ApiResourceDetails/index.tsx index aa489f376..d0f5493e1 100644 --- a/packages/console/src/pages/ApiResourceDetails/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/index.tsx @@ -33,7 +33,7 @@ const ApiResourceDetails = () => { const { id } = useParams(); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const navigate = useNavigate(); - const { data, error, mutate } = useSWR(id && `/api/resources/${id}`); + const { data, error, mutate } = useSWR(id && `api/resources/${id}`); const isLoading = !data && !error; const theme = useTheme(); const Icon = theme === AppearanceMode.LightMode ? ApiResource : ApiResourceDark; @@ -59,7 +59,7 @@ const ApiResourceDetails = () => { setIsDeleting(true); try { - await api.delete(`/api/resources/${data.id}`); + await api.delete(`api/resources/${data.id}`); toast.success(t('api_resource_details.api_resource_deleted', { name: data.name })); navigate(`/api-resources`); } finally { diff --git a/packages/console/src/pages/ApiResources/components/CreateForm/index.tsx b/packages/console/src/pages/ApiResources/components/CreateForm/index.tsx index 6d87757c5..d6738d722 100644 --- a/packages/console/src/pages/ApiResources/components/CreateForm/index.tsx +++ b/packages/console/src/pages/ApiResources/components/CreateForm/index.tsx @@ -33,7 +33,7 @@ const CreateForm = ({ onClose }: Props) => { return; } - const createdApiResource = await api.post('/api/resources', { json: data }).json(); + const createdApiResource = await api.post('api/resources', { json: data }).json(); onClose?.(createdApiResource); }); diff --git a/packages/console/src/pages/ApiResources/index.tsx b/packages/console/src/pages/ApiResources/index.tsx index a6325431f..3de0ff952 100644 --- a/packages/console/src/pages/ApiResources/index.tsx +++ b/packages/console/src/pages/ApiResources/index.tsx @@ -42,7 +42,7 @@ const ApiResources = () => { page: 1, }); - const url = buildUrl('/api/resources', { + const url = buildUrl('api/resources', { page: String(page), page_size: String(pageSize), }); diff --git a/packages/console/src/pages/ApplicationDetails/index.tsx b/packages/console/src/pages/ApplicationDetails/index.tsx index 0ca048528..ffd87e12f 100644 --- a/packages/console/src/pages/ApplicationDetails/index.tsx +++ b/packages/console/src/pages/ApplicationDetails/index.tsx @@ -43,7 +43,7 @@ const ApplicationDetails = () => { const { id } = useParams(); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { data, error, mutate } = useSWR( - id && `/api/applications/${id}` + id && `api/applications/${id}` ); const { data: oidcConfig, error: fetchOidcConfigError } = useSWR< SnakeCaseOidcConfig, @@ -79,7 +79,7 @@ const ApplicationDetails = () => { } await api - .patch(`/api/applications/${data.id}`, { + .patch(`api/applications/${data.id}`, { json: { ...formData, oidcClientMetadata: { @@ -108,7 +108,7 @@ const ApplicationDetails = () => { } try { - await api.delete(`/api/applications/${data.id}`); + await api.delete(`api/applications/${data.id}`); setIsDeleted(true); setIsDeleting(false); setIsDeleteFormOpen(false); diff --git a/packages/console/src/pages/Applications/components/CreateForm/index.tsx b/packages/console/src/pages/Applications/components/CreateForm/index.tsx index b8664f79b..a6c8d1ef1 100644 --- a/packages/console/src/pages/Applications/components/CreateForm/index.tsx +++ b/packages/console/src/pages/Applications/components/CreateForm/index.tsx @@ -55,7 +55,7 @@ const CreateForm = ({ onClose }: Props) => { return; } - const createdApp = await api.post('/api/applications', { json: data }).json(); + const createdApp = await api.post('api/applications', { json: data }).json(); setCreatedApp(createdApp); setIsGetStartedModalOpen(true); void updateConfigs({ applicationCreated: true }); diff --git a/packages/console/src/pages/Applications/index.tsx b/packages/console/src/pages/Applications/index.tsx index ffa25ace3..04ba0eff5 100644 --- a/packages/console/src/pages/Applications/index.tsx +++ b/packages/console/src/pages/Applications/index.tsx @@ -39,7 +39,7 @@ const Applications = () => { page: 1, }); - const url = buildUrl('/api/applications', { + const url = buildUrl('api/applications', { page: String(page), page_size: String(pageSize), }); diff --git a/packages/console/src/pages/AuditLogDetails/index.tsx b/packages/console/src/pages/AuditLogDetails/index.tsx index bc43021ae..ea676fd53 100644 --- a/packages/console/src/pages/AuditLogDetails/index.tsx +++ b/packages/console/src/pages/AuditLogDetails/index.tsx @@ -30,8 +30,8 @@ const AuditLogDetails = () => { const { id, logId } = useParams(); const { pathname } = useLocation(); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data, error } = useSWR(logId && `/api/logs/${logId}`); - const { data: userData } = useSWR(id && `/api/users/${id}`); + const { data, error } = useSWR(logId && `api/logs/${logId}`); + const { data: userData } = useSWR(id && `api/users/${id}`); const isLoading = !data && !error; diff --git a/packages/console/src/pages/ConnectorDetails/components/ConnectorContent.tsx b/packages/console/src/pages/ConnectorDetails/components/ConnectorContent.tsx index d814f71de..fa8406a35 100644 --- a/packages/console/src/pages/ConnectorDetails/components/ConnectorContent.tsx +++ b/packages/console/src/pages/ConnectorDetails/components/ConnectorContent.tsx @@ -83,7 +83,7 @@ const ConnectorContent = ({ isDeleted, connectorData, onConnectorUpdated }: Prop const body = connectorData.isStandard ? standardConnectorPayload : payload; const updatedConnector = await api - .patch(`/api/connectors/${connectorData.id}`, { + .patch(`api/connectors/${connectorData.id}`, { json: body, }) .json(); diff --git a/packages/console/src/pages/ConnectorDetails/components/ConnectorTabs/index.tsx b/packages/console/src/pages/ConnectorDetails/components/ConnectorTabs/index.tsx index d724e0287..5d8a5d17f 100644 --- a/packages/console/src/pages/ConnectorDetails/components/ConnectorTabs/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/components/ConnectorTabs/index.tsx @@ -18,7 +18,7 @@ type Props = { const ConnectorTabs = ({ target, connectorId }: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data: connectors } = useSWR(`/api/connectors?target=${target}`); + const { data: connectors } = useSWR(`api/connectors?target=${target}`); if (!connectors) { return null; diff --git a/packages/console/src/pages/ConnectorDetails/components/SenderTester/index.tsx b/packages/console/src/pages/ConnectorDetails/components/SenderTester/index.tsx index 9ef47cea7..bbea38b95 100644 --- a/packages/console/src/pages/ConnectorDetails/components/SenderTester/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/components/SenderTester/index.tsx @@ -69,7 +69,7 @@ const SenderTester = ({ connectorId, connectorType, config, className }: Props) const data = { config: result.data, ...(isSms ? { phone: sendTo } : { email: sendTo }) }; - await api.post(`/api/connectors/${connectorId}/test`, { json: data }).json(); + await api.post(`api/connectors/${connectorId}/test`, { json: data }).json(); setShowTooltip(true); }); diff --git a/packages/console/src/pages/ConnectorDetails/index.tsx b/packages/console/src/pages/ConnectorDetails/index.tsx index 5ab9c4a0a..5bed9722b 100644 --- a/packages/console/src/pages/ConnectorDetails/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/index.tsx @@ -47,10 +47,10 @@ const ConnectorDetails = () => { const [isSetupOpen, setIsSetupOpen] = useState(false); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { data, error, mutate } = useSWR( - connectorId && `/api/connectors/${connectorId}` + connectorId && `api/connectors/${connectorId}` ); const { data: connectorFactory } = useSWR( - data?.isStandard && `/api/connector-factories/${data.connectorId}` + data?.isStandard && `api/connector-factories/${data.connectorId}` ); const { isConnectorInUse } = useConnectorInUse(); const inUse = isConnectorInUse(data); @@ -79,12 +79,12 @@ const ConnectorDetails = () => { return; } - await api.delete(`/api/connectors/${connectorId}`).json(); + await api.delete(`api/connectors/${connectorId}`).json(); setIsDeleted(true); toast.success(t('connector_details.connector_deleted')); - await mutateGlobal('/api/connectors'); + await mutateGlobal('api/connectors'); navigate(getConnectorsPathname(isSocial), { replace: true, diff --git a/packages/console/src/pages/Connectors/components/ConnectorTypeColumn/index.tsx b/packages/console/src/pages/Connectors/components/ConnectorTypeColumn/index.tsx index 06dff0574..fd267cf4a 100644 --- a/packages/console/src/pages/Connectors/components/ConnectorTypeColumn/index.tsx +++ b/packages/console/src/pages/Connectors/components/ConnectorTypeColumn/index.tsx @@ -22,7 +22,7 @@ const ConnectorTypeColumn = ({ connectorGroup: { type, connectors } }: Props) => const firstStandardConnector = standardConnectors[0]; const { data: connectorFactory } = useSWR( - firstStandardConnector && `/api/connector-factories/${firstStandardConnector.connectorId}` + firstStandardConnector && `api/connector-factories/${firstStandardConnector.connectorId}` ); if (!firstStandardConnector) { diff --git a/packages/console/src/pages/Connectors/components/CreateForm/index.tsx b/packages/console/src/pages/Connectors/components/CreateForm/index.tsx index f3a363933..110bec4a1 100644 --- a/packages/console/src/pages/Connectors/components/CreateForm/index.tsx +++ b/packages/console/src/pages/Connectors/components/CreateForm/index.tsx @@ -29,11 +29,11 @@ const CreateForm = ({ onClose, isOpen: isFormOpen, type }: Props) => { const { data: existingConnectors, error: connectorsError } = useSWR< ConnectorResponse[], RequestError - >('/api/connectors'); + >('api/connectors'); const { data: factories, error: factoriesError } = useSWR< ConnectorFactoryResponse[], RequestError - >('/api/connector-factories'); + >('api/connector-factories'); const isLoading = !factories && !existingConnectors && !connectorsError && !factoriesError; const [activeGroupId, setActiveGroupId] = useState(); const [activeFactoryId, setActiveFactoryId] = useState(); diff --git a/packages/console/src/pages/Connectors/components/Guide/index.tsx b/packages/console/src/pages/Connectors/components/Guide/index.tsx index 2ab100810..bfbe4550a 100644 --- a/packages/console/src/pages/Connectors/components/Guide/index.tsx +++ b/packages/console/src/pages/Connectors/components/Guide/index.tsx @@ -84,7 +84,7 @@ const Guide = ({ connector, onClose }: Props) => { : basePayload; const createdConnector = await api - .post('/api/connectors', { + .post('api/connectors', { json: payload, }) .json(); diff --git a/packages/console/src/pages/Connectors/components/SignInExperienceSetupNotice/index.tsx b/packages/console/src/pages/Connectors/components/SignInExperienceSetupNotice/index.tsx index 8dba94ca5..ce199f8ae 100644 --- a/packages/console/src/pages/Connectors/components/SignInExperienceSetupNotice/index.tsx +++ b/packages/console/src/pages/Connectors/components/SignInExperienceSetupNotice/index.tsx @@ -10,7 +10,7 @@ import * as styles from './index.module.scss'; const SignInExperienceSetupNotice = () => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data: connectors } = useSWR('/api/connectors'); + const { data: connectors } = useSWR('api/connectors'); const { data: { connectorSieNoticeConfirmed }, update, diff --git a/packages/console/src/pages/Dashboard/index.tsx b/packages/console/src/pages/Dashboard/index.tsx index 7d60fbace..a07fef6a1 100644 --- a/packages/console/src/pages/Dashboard/index.tsx +++ b/packages/console/src/pages/Dashboard/index.tsx @@ -38,13 +38,13 @@ const tickFormatter = new Intl.NumberFormat('en-US', { const Dashboard = () => { const [date, setDate] = useState(format(Date.now(), 'yyyy-MM-dd')); const { data: totalData, error: totalError } = useSWR( - '/api/dashboard/users/total' + 'api/dashboard/users/total' ); const { data: newData, error: newError } = useSWR( - '/api/dashboard/users/new' + 'api/dashboard/users/new' ); const { data: activeData, error: activeError } = useSWR( - `/api/dashboard/users/active?date=${date}` + `api/dashboard/users/active?date=${date}` ); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); diff --git a/packages/console/src/pages/GetStarted/hook.ts b/packages/console/src/pages/GetStarted/hook.ts index e76b46fa9..0b3b0f732 100644 --- a/packages/console/src/pages/GetStarted/hook.ts +++ b/packages/console/src/pages/GetStarted/hook.ts @@ -40,7 +40,7 @@ const useGetStartedMetadata = () => { const theme = useTheme(); const isLightMode = theme === AppearanceMode.LightMode; const { data: demoApp, error } = useSWR( - `/api/applications/${demoAppApplicationId}`, + `api/applications/${demoAppApplicationId}`, { shouldRetryOnError: (error: unknown) => { if (error instanceof RequestError) { diff --git a/packages/console/src/pages/RoleDetails/RolePermissions/components/AssignPermissionsModal/index.tsx b/packages/console/src/pages/RoleDetails/RolePermissions/components/AssignPermissionsModal/index.tsx index d2b18dc5b..e7c6a1cb0 100644 --- a/packages/console/src/pages/RoleDetails/RolePermissions/components/AssignPermissionsModal/index.tsx +++ b/packages/console/src/pages/RoleDetails/RolePermissions/components/AssignPermissionsModal/index.tsx @@ -32,7 +32,7 @@ const AssignPermissionsModal = ({ roleId, onClose }: Props) => { setIsSubmitting(true); try { - await api.post(`/api/roles/${roleId}/scopes`, { + await api.post(`api/roles/${roleId}/scopes`, { json: { scopeIds: scopes.map(({ id }) => id) }, }); toast.success(t('role_details.permission.permission_assigned')); diff --git a/packages/console/src/pages/RoleDetails/RolePermissions/index.tsx b/packages/console/src/pages/RoleDetails/RolePermissions/index.tsx index fde74a06d..d3670d602 100644 --- a/packages/console/src/pages/RoleDetails/RolePermissions/index.tsx +++ b/packages/console/src/pages/RoleDetails/RolePermissions/index.tsx @@ -33,7 +33,7 @@ const RolePermissions = () => { const { data, error, mutate } = useSWR<[ScopeResponse[], number], RequestError>( roleId && - buildUrl(`/api/roles/${roleId}/scopes`, { + buildUrl(`api/roles/${roleId}/scopes`, { page: String(page), page_size: String(pageSize), ...conditional(keyword && { search: formatSearchKeyword(keyword) }), @@ -57,7 +57,7 @@ const RolePermissions = () => { setIsDeleting(true); try { - await api.delete(`/api/roles/${roleId}/scopes/${scopeToBeDeleted.id}`); + await api.delete(`api/roles/${roleId}/scopes/${scopeToBeDeleted.id}`); toast.success( t('role_details.permission.permission_deleted', { name: scopeToBeDeleted.name }) ); diff --git a/packages/console/src/pages/RoleDetails/RoleSettings/index.tsx b/packages/console/src/pages/RoleDetails/RoleSettings/index.tsx index 824b99034..9dfa15311 100644 --- a/packages/console/src/pages/RoleDetails/RoleSettings/index.tsx +++ b/packages/console/src/pages/RoleDetails/RoleSettings/index.tsx @@ -32,7 +32,7 @@ const RoleSettings = () => { return; } - const updatedRole = await api.patch(`/api/roles/${role.id}`, { json: formData }).json(); + const updatedRole = await api.patch(`api/roles/${role.id}`, { json: formData }).json(); reset(updatedRole); onRoleUpdated(updatedRole); toast.success(t('general.saved')); diff --git a/packages/console/src/pages/RoleDetails/RoleUsers/components/AssignUsersModal/index.tsx b/packages/console/src/pages/RoleDetails/RoleUsers/components/AssignUsersModal/index.tsx index b6c8800b0..8243fbf00 100644 --- a/packages/console/src/pages/RoleDetails/RoleUsers/components/AssignUsersModal/index.tsx +++ b/packages/console/src/pages/RoleDetails/RoleUsers/components/AssignUsersModal/index.tsx @@ -32,7 +32,7 @@ const AssignUsersModal = ({ roleId, isRemindSkip = false, onClose }: Props) => { setIsLoading(true); try { - await api.post(`/api/roles/${roleId}/users`, { + await api.post(`api/roles/${roleId}/users`, { json: { userIds: users.map(({ id }) => id) }, }); toast.success(t('role_details.users.users_assigned')); diff --git a/packages/console/src/pages/RoleDetails/RoleUsers/index.tsx b/packages/console/src/pages/RoleDetails/RoleUsers/index.tsx index bacd2924b..2ca365565 100644 --- a/packages/console/src/pages/RoleDetails/RoleUsers/index.tsx +++ b/packages/console/src/pages/RoleDetails/RoleUsers/index.tsx @@ -44,7 +44,7 @@ const RoleUsers = () => { const { data, error, mutate } = useSWR<[User[], number], RequestError>( roleId && - buildUrl(`/api/roles/${roleId}/users`, { + buildUrl(`api/roles/${roleId}/users`, { page: String(page), page_size: String(pageSize), ...conditional(keyword && { search: formatSearchKeyword(keyword) }), @@ -68,7 +68,7 @@ const RoleUsers = () => { setIsDeleting(true); try { - await api.delete(`/api/roles/${roleId}/users/${userToBeDeleted.id}`); + await api.delete(`api/roles/${roleId}/users/${userToBeDeleted.id}`); toast.success(t('role_details.users.deleted', { name: userToBeDeleted.name })); await mutate(); setUserToBeDeleted(undefined); diff --git a/packages/console/src/pages/RoleDetails/index.tsx b/packages/console/src/pages/RoleDetails/index.tsx index 12fab847b..6d2fa472c 100644 --- a/packages/console/src/pages/RoleDetails/index.tsx +++ b/packages/console/src/pages/RoleDetails/index.tsx @@ -33,7 +33,7 @@ const RoleDetails = () => { const isPageHasTable = pathname.endsWith(RoleDetailsTabs.Permissions) || pathname.endsWith(RoleDetailsTabs.Users); - const { data, error, mutate } = useSWR(id && `/api/roles/${id}`); + const { data, error, mutate } = useSWR(id && `api/roles/${id}`); const { mutate: mutateGlobal } = useSWRConfig(); const isLoading = !data && !error; @@ -55,9 +55,9 @@ const RoleDetails = () => { setIsDeleting(true); try { - await api.delete(`/api/roles/${data.id}`); + await api.delete(`api/roles/${data.id}`); toast.success(t('role_details.role_deleted', { name: data.name })); - await mutateGlobal('/api/roles'); + await mutateGlobal('api/roles'); navigate('/roles', { replace: true }); } finally { setIsDeleting(false); diff --git a/packages/console/src/pages/Roles/components/CreateRoleForm/index.tsx b/packages/console/src/pages/Roles/components/CreateRoleForm/index.tsx index 2375b87fc..9061d72ea 100644 --- a/packages/console/src/pages/Roles/components/CreateRoleForm/index.tsx +++ b/packages/console/src/pages/Roles/components/CreateRoleForm/index.tsx @@ -44,7 +44,7 @@ const CreateRoleForm = ({ onClose }: Props) => { scopeIds: conditional(scopes.length > 0 && scopes.map(({ id }) => id)), }; - const createdRole = await api.post('/api/roles', { json: payload }).json(); + const createdRole = await api.post('api/roles', { json: payload }).json(); onClose(createdRole); }); diff --git a/packages/console/src/pages/Roles/index.tsx b/packages/console/src/pages/Roles/index.tsx index 6f52d7f5b..434970cf6 100644 --- a/packages/console/src/pages/Roles/index.tsx +++ b/packages/console/src/pages/Roles/index.tsx @@ -37,7 +37,7 @@ const Roles = () => { keyword: '', }); - const url = buildUrl('/api/roles', { + const url = buildUrl('api/roles', { page: String(page), page_size: String(pageSize), ...conditional(keyword && { search: formatSearchKeyword(keyword) }), diff --git a/packages/console/src/pages/Settings/components/ChangePassword.tsx b/packages/console/src/pages/Settings/components/ChangePassword.tsx index 97e8372d2..76fb2da43 100644 --- a/packages/console/src/pages/Settings/components/ChangePassword.tsx +++ b/packages/console/src/pages/Settings/components/ChangePassword.tsx @@ -38,7 +38,7 @@ const ChangePassword = () => { } setIsLoading(true); - await api.patch(`/api/users/${userId}/password`, { json: { password } }).json(); + await api.patch(`api/users/${userId}/password`, { json: { password } }).json(); setIsLoading(false); setIsOpen(false); toast.success(t('settings.password_changed')); diff --git a/packages/console/src/pages/SignInExperience/components/Preview/index.tsx b/packages/console/src/pages/SignInExperience/components/Preview/index.tsx index cc9f7d355..ee1320360 100644 --- a/packages/console/src/pages/SignInExperience/components/Preview/index.tsx +++ b/packages/console/src/pages/SignInExperience/components/Preview/index.tsx @@ -27,7 +27,7 @@ const Preview = ({ signInExperience, className }: Props) => { const [language, setLanguage] = useState('en'); const [mode, setMode] = useState(AppearanceMode.LightMode); const [platform, setPlatform] = useState<'desktopWeb' | 'mobile' | 'mobileWeb'>('desktopWeb'); - const { data: allConnectors } = useSWR('/api/connectors'); + const { data: allConnectors } = useSWR('api/connectors'); const previewRef = useRef(null); const { customPhrases } = useUiLanguages(); diff --git a/packages/console/src/pages/SignInExperience/components/Welcome/GuideModal.tsx b/packages/console/src/pages/SignInExperience/components/Welcome/GuideModal.tsx index a04645ac0..2141a2deb 100644 --- a/packages/console/src/pages/SignInExperience/components/Welcome/GuideModal.tsx +++ b/packages/console/src/pages/SignInExperience/components/Welcome/GuideModal.tsx @@ -32,7 +32,7 @@ type Props = { }; const GuideModal = ({ isOpen, onClose }: Props) => { - const { data } = useSWR('/api/sign-in-exp'); + const { data } = useSWR('api/sign-in-exp'); const { data: preferences, update: updatePreferences } = useUserPreferences(); const { updateConfigs } = useConfigs(); const methods = useForm(); @@ -65,7 +65,7 @@ const GuideModal = ({ isOpen, onClose }: Props) => { } await Promise.all([ - api.patch('/api/sign-in-exp', { + api.patch('api/sign-in-exp', { json: signInExperienceParser.toRemoteModel(formData), }), updateConfigs({ signInExperienceCustomized: true }), diff --git a/packages/console/src/pages/SignInExperience/index.tsx b/packages/console/src/pages/SignInExperience/index.tsx index efe8c5b93..1d1aea376 100644 --- a/packages/console/src/pages/SignInExperience/index.tsx +++ b/packages/console/src/pages/SignInExperience/index.tsx @@ -39,7 +39,7 @@ import { const SignInExperience = () => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { tab } = useParams(); - const { data, error, mutate } = useSWR('/api/sign-in-exp'); + const { data, error, mutate } = useSWR('api/sign-in-exp'); const { configs, error: configsError, updateConfigs, mutate: mutateConfigs } = useConfigs(); const { error: languageError, isLoading: isLoadingLanguages } = useUiLanguages(); const [dataToCompare, setDataToCompare] = useState(); @@ -73,7 +73,7 @@ const SignInExperience = () => { const saveData = async () => { const updatedData = await api - .patch('/api/sign-in-exp', { + .patch('api/sign-in-exp', { json: signInExperienceParser.toRemoteModel(getValues()), }) .json(); diff --git a/packages/console/src/pages/SignInExperience/tabs/Others/LanguagesForm.tsx b/packages/console/src/pages/SignInExperience/tabs/Others/LanguagesForm.tsx index 8835f416e..21ca7a281 100644 --- a/packages/console/src/pages/SignInExperience/tabs/Others/LanguagesForm.tsx +++ b/packages/console/src/pages/SignInExperience/tabs/Others/LanguagesForm.tsx @@ -22,7 +22,7 @@ type Props = { const LanguagesForm = ({ isManageLanguageVisible = false }: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data: signInExperience } = useSWR('/api/sign-in-exp'); + const { data: signInExperience } = useSWR('api/sign-in-exp'); const { watch, control, register, setValue } = useFormContext(); const isAutoDetect = watch('languageInfo.autoDetect'); const selectedDefaultLanguage = watch('languageInfo.fallbackLanguage'); diff --git a/packages/console/src/pages/SignInExperience/tabs/Others/components/ManageLanguage/LanguageEditor/LanguageDetails.tsx b/packages/console/src/pages/SignInExperience/tabs/Others/components/ManageLanguage/LanguageEditor/LanguageDetails.tsx index 7a54aed85..df1ccf1f6 100644 --- a/packages/console/src/pages/SignInExperience/tabs/Others/components/ManageLanguage/LanguageEditor/LanguageDetails.tsx +++ b/packages/console/src/pages/SignInExperience/tabs/Others/components/ManageLanguage/LanguageEditor/LanguageDetails.tsx @@ -35,7 +35,7 @@ const emptyUiTranslation = createEmptyUiTranslation(); const LanguageDetails = () => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data: signInExperience } = useSWR('/api/sign-in-exp'); + const { data: signInExperience } = useSWR('api/sign-in-exp'); const { languages } = useUiLanguages(); @@ -53,7 +53,7 @@ const LanguageDetails = () => { ); const { data: customPhrase, mutate } = useSWR( - `/api/custom-phrases/${selectedLanguage}`, + `api/custom-phrases/${selectedLanguage}`, { shouldRetryOnError: (error: unknown) => { if (error instanceof RequestError) { @@ -104,14 +104,14 @@ const LanguageDetails = () => { const upsertCustomPhrase = useCallback( async (languageTag: LanguageTag, translation: Translation) => { const updatedCustomPhrase = await api - .put(`/api/custom-phrases/${languageTag}`, { + .put(`api/custom-phrases/${languageTag}`, { json: { ...cleanDeep(translation), }, }) .json(); - void globalMutate('/api/custom-phrases'); + void globalMutate('api/custom-phrases'); return updatedCustomPhrase; }, @@ -125,9 +125,9 @@ const LanguageDetails = () => { return; } - await api.delete(`/api/custom-phrases/${selectedLanguage}`); + await api.delete(`api/custom-phrases/${selectedLanguage}`); - await globalMutate('/api/custom-phrases'); + await globalMutate('api/custom-phrases'); setSelectedLanguage(languages.find((languageTag) => languageTag !== selectedLanguage) ?? 'en'); }, [api, globalMutate, isDefaultLanguage, languages, selectedLanguage, setSelectedLanguage]); diff --git a/packages/console/src/pages/UserDetails/UserRoles/components/AssignRolesModal/index.tsx b/packages/console/src/pages/UserDetails/UserRoles/components/AssignRolesModal/index.tsx index 686cb7d0e..b2b1d2885 100644 --- a/packages/console/src/pages/UserDetails/UserRoles/components/AssignRolesModal/index.tsx +++ b/packages/console/src/pages/UserDetails/UserRoles/components/AssignRolesModal/index.tsx @@ -34,7 +34,7 @@ const AssignRolesModal = ({ user, onClose }: Props) => { setIsSubmitting(true); try { - await api.post(`/api/users/${user.id}/roles`, { + await api.post(`api/users/${user.id}/roles`, { json: { roleIds: roles.map(({ id }) => id) }, }); toast.success(t('user_details.roles.role_assigned')); diff --git a/packages/console/src/pages/UserDetails/UserRoles/index.tsx b/packages/console/src/pages/UserDetails/UserRoles/index.tsx index 333ff210e..1c6a8a74d 100644 --- a/packages/console/src/pages/UserDetails/UserRoles/index.tsx +++ b/packages/console/src/pages/UserDetails/UserRoles/index.tsx @@ -39,7 +39,7 @@ const UserRoles = () => { }); const { data, error, mutate } = useSWR<[Role[], number], RequestError>( - buildUrl(`/api/users/${userId}/roles`, { + buildUrl(`api/users/${userId}/roles`, { page: String(page), page_size: String(pageSize), ...conditional(keyword && { search: formatSearchKeyword(keyword) }), @@ -63,7 +63,7 @@ const UserRoles = () => { setIsDeleting(true); try { - await api.delete(`/api/users/${userId}/roles/${roleToBeDeleted.id}`); + await api.delete(`api/users/${userId}/roles/${roleToBeDeleted.id}`); toast.success(t('user_details.roles.deleted', { name: roleToBeDeleted.name })); await mutate(); setRoleToBeDeleted(undefined); diff --git a/packages/console/src/pages/UserDetails/UserSettings/components/UserSocialIdentities/index.tsx b/packages/console/src/pages/UserDetails/UserSettings/components/UserSocialIdentities/index.tsx index 7e49f3040..2dc1bfabd 100644 --- a/packages/console/src/pages/UserDetails/UserSettings/components/UserSocialIdentities/index.tsx +++ b/packages/console/src/pages/UserDetails/UserSettings/components/UserSocialIdentities/index.tsx @@ -34,7 +34,7 @@ const ConnectorName = ({ name }: { name: DisplayConnector['name'] }) => const UserSocialIdentities = ({ userId, identities, onDelete }: Props) => { const api = useApi(); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const { data, error, mutate } = useSWR('/api/connectors'); + const { data, error, mutate } = useSWR('api/connectors'); const [deletingConnector, setDeletingConnector] = useState(); const [isSubmitting, setIsSubmitting] = useState(false); @@ -56,7 +56,7 @@ const UserSocialIdentities = ({ userId, identities, onDelete }: Props) => { setIsSubmitting(true); try { - await api.delete(`/api/users/${userId}/identities/${target}`); + await api.delete(`api/users/${userId}/identities/${target}`); onDelete?.(target); } finally { setIsSubmitting(false); diff --git a/packages/console/src/pages/UserDetails/UserSettings/index.tsx b/packages/console/src/pages/UserDetails/UserSettings/index.tsx index cc49b64fc..fc1e79dfe 100644 --- a/packages/console/src/pages/UserDetails/UserSettings/index.tsx +++ b/packages/console/src/pages/UserDetails/UserSettings/index.tsx @@ -72,7 +72,7 @@ const UserSettings = () => { customData: guardResult.data, }; - const updatedUser = await api.patch(`/api/users/${user.id}`, { json: payload }).json(); + const updatedUser = await api.patch(`api/users/${user.id}`, { json: payload }).json(); reset(userDetailsParser.toLocalForm(updatedUser)); onUserUpdated(updatedUser); toast.success(t('general.saved')); diff --git a/packages/console/src/pages/UserDetails/components/ResetPasswordForm/index.tsx b/packages/console/src/pages/UserDetails/components/ResetPasswordForm/index.tsx index 9f9c6cfcf..2b516cb26 100644 --- a/packages/console/src/pages/UserDetails/components/ResetPasswordForm/index.tsx +++ b/packages/console/src/pages/UserDetails/components/ResetPasswordForm/index.tsx @@ -21,7 +21,7 @@ const ResetPasswordForm = ({ onClose, userId }: Props) => { const onSubmit = async () => { const password = nanoid(8); setIsLoading(true); - await api.patch(`/api/users/${userId}/password`, { json: { password } }).json(); + await api.patch(`api/users/${userId}/password`, { json: { password } }).json(); setIsLoading(false); onClose?.(password); }; diff --git a/packages/console/src/pages/UserDetails/index.tsx b/packages/console/src/pages/UserDetails/index.tsx index 6af31d741..77507e54b 100644 --- a/packages/console/src/pages/UserDetails/index.tsx +++ b/packages/console/src/pages/UserDetails/index.tsx @@ -41,7 +41,7 @@ const UserDetails = () => { const [isResetPasswordFormOpen, setIsResetPasswordFormOpen] = useState(false); const [resetResult, setResetResult] = useState(); - const { data, error, mutate } = useSWR(id && `/api/users/${id}`); + const { data, error, mutate } = useSWR(id && `api/users/${id}`); const isLoading = !data && !error; const api = useApi(); const navigate = useNavigate(); @@ -59,7 +59,7 @@ const UserDetails = () => { setIsDeleting(true); try { - await api.delete(`/api/users/${data.id}`); + await api.delete(`api/users/${data.id}`); toast.success(t('user_details.deleted', { name: data.name })); navigate('/users'); } finally { diff --git a/packages/console/src/pages/Users/components/CreateForm/index.tsx b/packages/console/src/pages/Users/components/CreateForm/index.tsx index 915e06ee6..2c77c0961 100644 --- a/packages/console/src/pages/Users/components/CreateForm/index.tsx +++ b/packages/console/src/pages/Users/components/CreateForm/index.tsx @@ -51,7 +51,7 @@ const CreateForm = ({ onClose, onCreate }: Props) => { const password = nanoid(8); - const createdUser = await api.post('/api/users', { json: { ...data, password } }).json(); + const createdUser = await api.post('api/users', { json: { ...data, password } }).json(); setCreatedUserInfo({ user: createdUser, diff --git a/packages/console/src/pages/Users/index.tsx b/packages/console/src/pages/Users/index.tsx index cf2456f93..8f46b211c 100644 --- a/packages/console/src/pages/Users/index.tsx +++ b/packages/console/src/pages/Users/index.tsx @@ -38,7 +38,7 @@ const Users = () => { keyword: '', }); - const url = buildUrl('/api/users', { + const url = buildUrl('api/users', { hideAdminUser: String(true), page: String(page), page_size: String(pageSize),