diff --git a/src/actions/apps.ts b/src/actions/apps.ts index cc68d24..b976e13 100644 --- a/src/actions/apps.ts +++ b/src/actions/apps.ts @@ -19,7 +19,7 @@ export const fetchApps = (sort?: string, continuation?: string): AppThunkAction try { const response = await apiFetch({ - path: `/api/apps?${objectToQuerystring({ sort, continuation })}`, + path: `/v1/apps?${objectToQuerystring({ sort, continuation })}`, }) const apps = normalize(response.apps, EntityType.App) @@ -44,7 +44,7 @@ export const fetchCreatedApps = (sort?: string): AppThunkAction => async dispatc try { const response = await apiFetch({ - path: `/api/self/apps?${objectToQuerystring({ sort })}`, + path: `/v1/self/apps?${objectToQuerystring({ sort })}`, }) const apps = normalize(response.apps, EntityType.App) @@ -63,7 +63,7 @@ export const checkAppAvailability = (name: string): AppThunkAction => async disp try { const { id, available } = await apiFetch({ - path: '/api/app/available', + path: '/v1/app/available', method: 'post', body: { name, @@ -106,7 +106,7 @@ export const createApp = (options: AppOptions): AppThunkAction => async try { const { id } = await apiFetch({ - path: '/api/app', + path: '/v1/app', method: 'post', body: { name, @@ -136,7 +136,7 @@ export const updateApp = (id: string, options: AppOptions): AppThunkAction => as try { await apiFetch({ - path: `/api/app/${id}`, + path: `/v1/app/${id}`, method: 'put', body: { name, @@ -164,7 +164,7 @@ export const fetchApp = (id: string): AppThunkAction => async dispatch => { try { const app = await apiFetch({ - path: `/api/app/${id}`, + path: `/v1/app/${id}`, method: 'get', }) @@ -182,7 +182,7 @@ export const installApp = (id: string): AppThunkAction => async dispatch => { try { await apiFetch({ - path: `/api/app/${id}/install`, + path: `/v1/app/${id}/install`, method: 'post' }) @@ -198,7 +198,7 @@ export const uninstallApp = (id: string): AppThunkAction => async dispatch => { try { await apiFetch({ - path: `/api/app/${id}/uninstall`, + path: `/v1/app/${id}/uninstall`, method: 'post' }) diff --git a/src/actions/authentication.ts b/src/actions/authentication.ts index f186e95..38f8d10 100644 --- a/src/actions/authentication.ts +++ b/src/actions/authentication.ts @@ -56,7 +56,7 @@ export const fetchSelf = (): AppThunkAction => async dispatch => { try { const self = await apiFetch({ - path: '/api/self', + path: '/v1/self', }) const result = normalize([self], EntityType.User) @@ -85,7 +85,7 @@ export const authenticate = (name: string, password: string): AppThunkAction({ - path: '/api/authenticate', + path: '/v1/authenticate', method: 'post', body: { id: name, @@ -124,7 +124,7 @@ export const updateSelf = (options: UpdateSelfOptions): AppThunkAction => async try { const self = await apiFetch({ - path: '/api/self', + path: '/v1/self', method: 'put', body: { name, diff --git a/src/actions/composer.ts b/src/actions/composer.ts index 77c82b4..515ab2d 100644 --- a/src/actions/composer.ts +++ b/src/actions/composer.ts @@ -57,7 +57,7 @@ export const fetchInstallations = (): AppThunkAction => async dispatch => { try { const response = await apiFetch({ - path: '/api/installations', + path: '/v1/installations', }) const result = normalize(response.installations, EntityType.Installation) @@ -76,7 +76,7 @@ export const saveInstallationSettings = (id: string, settings: Settings): AppThu try { await apiFetch({ - path: `/api/installation/${id}/settings`, + path: `/v1/installation/${id}/settings`, method: 'put', body: { settings }, }) diff --git a/src/actions/groups.ts b/src/actions/groups.ts index ccbd743..bdc5a00 100644 --- a/src/actions/groups.ts +++ b/src/actions/groups.ts @@ -15,7 +15,7 @@ export const fetchGroup = (id: string): AppThunkAction => { try { const group = await apiFetch({ - path: `/api/group/${id}` + path: `/v1/group/${id}` }) const groups = normalize([group], EntityType.Group) @@ -39,7 +39,7 @@ export const fetchGroups = (sort?: string, continuation?: string): AppThunkActio try { const response = await apiFetch({ - path: `/api/groups?${objectToQuerystring({ sort, continuation })}`, + path: `/v1/groups?${objectToQuerystring({ sort, continuation })}`, }) const groups = normalize(response.groups, EntityType.Group) @@ -69,7 +69,7 @@ export const fetchGroupMembers = (id: string, type?: string, continuation?: stri try { const response = await apiFetch({ - path: `/api/group/${id}/members?${objectToQuerystring({ type, continuation })}`, + path: `/v1/group/${id}/members?${objectToQuerystring({ type, continuation })}`, }) const users = normalize(response.members, EntityType.User) @@ -94,12 +94,12 @@ interface GroupLogsResponse { continuation?: string } -export const fetchLogs = (id: string, continuation?: string): AppThunkAction => async dispatch => { +export const fetchLogs = (continuation?: string): AppThunkAction => async dispatch => { dispatch(startRequest(RequestKey.FetchGroupLogs)) try { const response = await apiFetch({ - path: `/api/group/${id}/logs?${objectToQuerystring({ continuation })}`, + path: `/v1/group/logs?${objectToQuerystring({ continuation })}`, }) const logs = normalize(response.logs, EntityType.Log) @@ -123,12 +123,12 @@ interface CreateInvitationResponse { code: string } -export const createInvitation = (id: string, expiration?: number, limit?: number): AppThunkAction => async dispatch => { +export const createInvitation = (expiration?: number, limit?: number): AppThunkAction => async dispatch => { dispatch(startRequest(RequestKey.CreateInvitation)) try { const response = await apiFetch({ - path: `/api/group/${id}/invitation`, + path: `/v1/group/invitation`, method: 'post', body: { expiration, @@ -149,12 +149,12 @@ interface InvitationsResponse { continuation?: string } -export const fetchInvitations = (id: string): AppThunkAction => async dispatch => { +export const fetchInvitations = (): AppThunkAction => async dispatch => { dispatch(startRequest(RequestKey.FetchInvitations)) try { const response = await apiFetch({ - path: `/api/group/${id}/invitations`, + path: `/v1/group/invitations`, }) const invitations = normalize(response.invitations, EntityType.Invitation) @@ -173,7 +173,7 @@ export const updateGroup = (id: string, updates: object): AppThunkAction => asyn try { await apiFetch({ - path: `/api/group/${id}`, + path: `/v1/group/${id}`, method: 'put', body: updates, }) diff --git a/src/actions/posts.ts b/src/actions/posts.ts index 03f1a75..88db5d4 100644 --- a/src/actions/posts.ts +++ b/src/actions/posts.ts @@ -30,7 +30,7 @@ export const createPost = (options: CreatePostOptions): AppThunkAction = try { const post = await apiFetch({ - path: `/api/post`, + path: `/v1/post`, method: 'post', body: { installation, @@ -65,7 +65,7 @@ export const fetchPost = (id: string): AppThunkAction => { try { const response = await apiFetch({ - path: `/api/post/${id}` + path: `/v1/post/${id}` }) const parents = normalize(response.parents.map(p => ({ @@ -113,7 +113,7 @@ export const fetchTimeline = (continuation?: string): AppThunkAction => async di try { const response = await apiFetch({ - path: `/api/timeline?${objectToQuerystring({ continuation })}`, + path: `/v1/timeline?${objectToQuerystring({ continuation })}`, }) const posts = normalize(response.posts, EntityType.Post) @@ -144,7 +144,7 @@ export const fetchUserPosts = (id: string, continuation?: string): AppThunkActio try { const response = await apiFetch({ - path: `/api/user/${id}/posts`, + path: `/v1/user/${id}/posts`, }) const posts = normalize(response.posts.map(p => ({ diff --git a/src/actions/registration.ts b/src/actions/registration.ts index 072a5cf..b421f38 100644 --- a/src/actions/registration.ts +++ b/src/actions/registration.ts @@ -28,7 +28,7 @@ export const checkGroupAvailability = (name: string): AppThunkAction => async di try { const { id, available } = await apiFetch({ - path: '/api/group/available', + path: '/v1/group/available', method: 'post', body: { name, @@ -53,7 +53,7 @@ export const checkUserAvailability = (name: string): AppThunkAction => async dis try { const { id, available } = await apiFetch({ - path: '/api/user/available', + path: '/v1/user/available', method: 'post', body: { name, @@ -94,7 +94,7 @@ export const createGroup = (options: CreateGroupOptions): AppThunkAction try { const { id } = await apiFetch({ - path: '/api/group', + path: '/v1/group', method: 'post', body: { name, @@ -142,7 +142,7 @@ export const register = (options: RegisterOptions): AppThunkAction => as try { const response = await apiFetch({ - path: '/api/register', + path: '/v1/register', method: 'post', body: { id, diff --git a/src/actions/users.ts b/src/actions/users.ts index cba7494..b6e9b3a 100644 --- a/src/actions/users.ts +++ b/src/actions/users.ts @@ -10,7 +10,7 @@ export const fetchUser = (id: string): AppThunkAction => { try { const user = await apiFetch({ - path: `/api/user/${id}` + path: `/v1/user/${id}` }) const users = normalize([user], EntityType.User) @@ -30,7 +30,7 @@ export const subscribe = (id: string): AppThunkAction => { try { await apiFetch({ - path: `/api/user/${id}/subscribe`, + path: `/v1/user/${id}/subscribe`, method: 'post', }) @@ -48,7 +48,7 @@ export const unsubscribe = (id: string): AppThunkAction => { try { await apiFetch({ - path: `/api/user/${id}/unsubscribe`, + path: `/v1/user/${id}/unsubscribe`, method: 'post', }) diff --git a/src/api/fetch.ts b/src/api/fetch.ts index 3b9095e..2c1ec5a 100644 --- a/src/api/fetch.ts +++ b/src/api/fetch.ts @@ -96,7 +96,7 @@ export const apiFetch: APIFetch = async (options: FetchOptions) => { const refreshToken = localStorage.getItem(LOCAL_STORAGE_REFRESH_TOKEN_KEY) if (accessToken && refreshToken) { - const refreshResponse = await fetch(`${config.apiUrl}/api/refresh`, { + const refreshResponse = await fetch(`${config.apiUrl}/v1/refresh`, { headers: new Headers({ 'Content-Type': contentType, 'Authorization': `Bearer ${accessToken}` diff --git a/src/components/controls/file-field.tsx b/src/components/controls/file-field.tsx index 02c5cc8..d69dc04 100644 --- a/src/components/controls/file-field.tsx +++ b/src/components/controls/file-field.tsx @@ -45,7 +45,7 @@ const FileField: FC = props => { } const ext = file.name.substring(file.name.lastIndexOf('.')) - const { sas, id } = await apiFetch({ path: '/api/sas' }) + const { sas, id } = await apiFetch({ path: '/v1/sas' }) const filename = `${id}${ext}` setUploading(true) @@ -59,7 +59,7 @@ const FileField: FC = props => { }) await apiFetch({ - path: '/api/media', + path: '/v1/media', method: 'post', body: { name: filename, @@ -83,11 +83,8 @@ const FileField: FC = props => { const handleDelete = async () => { if (uploaded) { await apiFetch({ - path: '/api/media/delete', - method: 'post', - body: { - name: value, - } + path: `/v1/media?name=${value}`, + method: 'delete', }) } diff --git a/src/components/group-invitations.tsx b/src/components/group-invitations.tsx index d9f8247..efe6652 100644 --- a/src/components/group-invitations.tsx +++ b/src/components/group-invitations.tsx @@ -31,8 +31,8 @@ const GroupInvitations: FC = ({ group }) => { const handleCreateInvitation = async () => { try { - await dispatch(createInvitation(group, moment().add(expiration, 'day').valueOf(), parseInt(limit, 10))) - await dispatch(fetchInvitations(group)) + await dispatch(createInvitation(moment().add(expiration, 'day').valueOf(), parseInt(limit, 10))) + await dispatch(fetchInvitations()) } catch (err) { handleApiError(err, dispatch, history) } @@ -41,7 +41,7 @@ const GroupInvitations: FC = ({ group }) => { useEffect(() => { if (invitations.length === 0) { try { - dispatch(fetchInvitations(group)) + dispatch(fetchInvitations()) } catch (err) { handleApiError(err, dispatch, history) } diff --git a/src/types/index.ts b/src/types/index.ts index eeec2ae..75e17df 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,7 +2,7 @@ import { AnyAction } from 'redux' import { ThunkDispatch, ThunkAction } from 'redux-thunk' import { AppState } from './store' -export type FetchMethods = 'get' | 'post' | 'put' +export type FetchMethods = 'get' | 'post' | 'put' | 'delete' export interface FetchOptions { path: string