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

Update URLs in routes.ts #265

Merged
merged 6 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/rare-vans-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'mexit': patch
'mexit-webapp': patch
---

Sanitize apiURLs file; Move to staging
2 changes: 1 addition & 1 deletion apps/extension/src/Components/Dibba/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function Dibba() {
type: 'Public Nodes',
id: nodeID,
icon: 'ri:external-link-line',
url: apiURLs.getPublicNodePath(nodeID),
url: apiURLs.frontend.getPublicNodePath(nodeID),
title: getPathFromNodeIdHookless(nodeID).split(SEPARATOR).pop(),
content: _content?.content || defaultContent.content
}
Expand Down
10 changes: 5 additions & 5 deletions apps/extension/src/Hooks/useNodeShareAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useNodeShareAPI = () => {
accessType: access
}
return await client
.post(apiURLs.sharedNode, payload, {
.post(apiURLs.share.sharedNode, payload, {
headers: {
'mex-workspace-id': workspaceDetails.id
}
Expand All @@ -45,7 +45,7 @@ export const useNodeShareAPI = () => {
userIDToAccessTypeMap
}
return await client
.put(apiURLs.sharedNode, payload, {
.put(apiURLs.share.sharedNode, payload, {
headers: {
'mex-workspace-id': workspaceDetails.id
}
Expand All @@ -63,7 +63,7 @@ export const useNodeShareAPI = () => {
userIDs: userids
}
return await client
.delete(apiURLs.sharedNode, {
.delete(apiURLs.share.sharedNode, {
data: payload,
headers: {
'mex-workspace-id': workspaceDetails.id
Expand All @@ -78,7 +78,7 @@ export const useNodeShareAPI = () => {
const getAllSharedNodes = async (): Promise<SharedNodesPreset | SharedNodesErrorPreset> => {
try {
return await client
.get(apiURLs.allSharedNodes, {
.get(apiURLs.share.allSharedNodes, {
headers: {
'mex-workspace-id': workspaceDetails.id
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export const useNodeShareAPI = () => {
const getUsersOfSharedNode = async (nodeid: string): Promise<{ nodeid: string; users: Record<string, string> }> => {
try {
return await client
.get(apiURLs.getUsersOfSharedNode(nodeid), {
.get(apiURLs.share.getUsersOfSharedNode(nodeid), {
headers: {
'mex-workspace-id': workspaceDetails.id
}
Expand Down
14 changes: 7 additions & 7 deletions apps/extension/src/Utils/requestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const handleCaptureRequest = ({ subType, data }) => {
}

return client
.post(apiURLs.createNode, reqData, {
.post(apiURLs.node.create, reqData, {
headers: {
'mex-workspace-id': data.workspaceID
}
Expand Down Expand Up @@ -54,7 +54,7 @@ export const handleCaptureRequest = ({ subType, data }) => {
tags: []
}
return client
.post(apiURLs.bulkCreateNodes, reqData, {
.post(apiURLs.node.bulkCreate, reqData, {
headers: {
'mex-workspace-id': data.workspaceID
}
Expand Down Expand Up @@ -85,7 +85,7 @@ export const handleSharingRequest = ({ subType, body, headers }) => {
switch (subType) {
case 'MAKE_PUBLIC': {
return client
.patch(apiURLs.makeNotePublic(body?.nodeId), null, {
.patch(apiURLs.node.makePublic(body?.nodeId), null, {
withCredentials: false,
headers: headers
})
Expand All @@ -98,7 +98,7 @@ export const handleSharingRequest = ({ subType, body, headers }) => {
}
case 'MAKE_PRIVATE': {
return client
.patch(apiURLs.makeNotePrivate(body?.nodeId), null, {
.patch(apiURLs.node.makePrivate(body?.nodeId), null, {
withCredentials: false,
headers: headers
})
Expand Down Expand Up @@ -196,7 +196,7 @@ export const handleAsyncActionRequest = ({ subType, data }) => {

// TODO: complete this
case 'MEX_USER': {
const URL = apiURLs.getUserByLinkedin
const URL = apiURLs.user.getUserByLinkedin

return client
.post(URL, data.body)
Expand Down Expand Up @@ -231,15 +231,15 @@ export const handleAsyncActionRequest = ({ subType, data }) => {
case 'UPLOAD_IMAGE': {
return client
.post(
apiURLs.createImageLink,
apiURLs.misc.createImageLink,
{ encodedString: data.base64 },
{
headers: { 'workspace-id': data.workspaceId }
}
)
.then((resp) => resp.data)
.then((path: string) => {
return { message: apiURLs.getImagePublicLink(path), error: null }
return { message: apiURLs.misc.getImagePublicLink(path), error: null }
})
.catch((error) => {
return { message: null, error: error }
Expand Down
4 changes: 2 additions & 2 deletions apps/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Sentry from '@sentry/browser'
import { CaptureConsole } from '@sentry/integrations'
import fuzzysort from 'fuzzysort'

import { ActionType, apiURLs, LINK_SHORTENER_URL_BASE, mog, SEPARATOR } from '@mexit/core'
import { ActionType, LINK_SHORTENER_URL_BASE, SEPARATOR, MEXIT_FRONTEND_URL_BASE } from '@mexit/core'

import { useAuthStore } from './Hooks/useAuth'
import useDataStore from './Stores/useDataStore'
Expand All @@ -21,7 +21,7 @@ Sentry.init({

chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
const url = apiURLs.mexitHome
const url = MEXIT_FRONTEND_URL_BASE
chrome.tabs.create(
{
url: url,
Expand Down
2 changes: 0 additions & 2 deletions apps/webapp/src/Components/Editor/Banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ const Banner: React.FC<BannerType> = ({

const isUserOnly = activeUsers.includes(currentUser?.userID)

if (activeUsers?.length === 1 && isUserOnly) return

return (
<BannerContainer>
<Group>
Expand Down
6 changes: 3 additions & 3 deletions apps/webapp/src/Components/EditorInfobar/ShareOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ const ShareOptions = ({ context, id }: ShareOptionsProps) => {

const publicUrl = useMemo(() => {
if (context === 'note') {
return isPublic(id) ? apiURLs.getPublicNodePath(id) : undefined
return isPublic(id) ? apiURLs.frontend.getPublicNodePath(id) : undefined
} else if (context === 'space') {
return isNamespacePublic(id) ? apiURLs.namespaces.getPublicURL(id) : undefined
return isNamespacePublic(id) ? apiURLs.frontend.getPublicNSURL(id) : undefined
}
}, [id, isPublic, context, isNamespacePublic])

const noteNamespacePublicLink = useMemo(() => {
if (context === 'note') {
const namespace = getNamespaceOfNodeid(id)
return namespace && isNamespacePublic(namespace.id)
? apiURLs.namespaces.getPublicURLofNote(namespace.id, id)
? apiURLs.frontend.getPublicURLofNoteInNS(namespace.id, id)
: undefined
}
return undefined
Expand Down
5 changes: 3 additions & 2 deletions apps/webapp/src/Hooks/API/useNamespaceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export const useNamespaceApi = () => {
fulfilled.forEach((nodes) => {
if (nodes) {
const { rawResponse } = nodes
setRequest(apiURLs.getMultipleNode(), { ...requestData, url: apiURLs.getMultipleNode() })
setRequest(apiURLs.node.getMultipleNode, { ...requestData, url: apiURLs.node.getMultipleNode })

if (rawResponse) {
rawResponse.map((nodeResponse) => {
const metadata = extractMetadata(nodeResponse) // added by Varshitha
Expand Down Expand Up @@ -131,7 +132,7 @@ export const useNamespaceApi = () => {

const getPublicNamespaceAPI = async (namespaceID: string) => {
const res = await client
.get(apiURLs.namespaces.getPublic(namespaceID), {
.get(apiURLs.public.getPublicNS(namespaceID), {
headers: workspaceHeaders()
})
.then((response: any) => {
Expand Down
46 changes: 31 additions & 15 deletions apps/webapp/src/Hooks/API/useNodeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const useApi = () => {
setContent(noteID, options.content ?? defaultContent.content)

const data = await client
.post(apiURLs.createNode, reqData, {
.post(apiURLs.node.create, reqData, {
headers: workspaceHeaders()
})
.then((d: any) => {
Expand Down Expand Up @@ -120,7 +120,7 @@ export const useApi = () => {
setContent(noteID, options.content)

const data = await client
.post(apiURLs.bulkCreateNodes, reqData, {
.post(apiURLs.node.bulkCreate, reqData, {
headers: workspaceHeaders()
})
.then((d: any) => {
Expand Down Expand Up @@ -148,7 +148,7 @@ export const useApi = () => {
}

// * TODO: Add append to Note for shared notes
const url = apiURLs.appendNode(noteId)
const url = apiURLs.node.append(noteId)

const res = await client.patch(url, reqData, { headers: workspaceHeaders() })

Expand Down Expand Up @@ -187,7 +187,7 @@ export const useApi = () => {
reqData['namespaceID'] = undefined
}

const url = isShared ? apiURLs.updateSharedNode : apiURLs.createNode
const url = isShared ? apiURLs.share.updateNode : apiURLs.node.create
const data = await client
.post(url, reqData, {
headers: workspaceHeaders()
Expand All @@ -211,7 +211,7 @@ export const useApi = () => {
}

const getDataAPI = async (nodeid: string, isShared = false, isRefresh = false, isUpdate = true) => {
const url = isShared ? apiURLs.getSharedNode(nodeid) : apiURLs.getNode(nodeid)
const url = isShared ? apiURLs.share.getSharedNode(nodeid) : apiURLs.node.get(nodeid)
if (!isShared && isRequestedWithin(GET_REQUEST_MINIMUM_GAP, url) && !isRefresh) {
console.warn('\nAPI has been requested before, cancelling\n')
return
Expand Down Expand Up @@ -239,7 +239,7 @@ export const useApi = () => {
}

const makeNotePublic = async (nodeId: string) => {
const URL = apiURLs.makeNotePublic(nodeId)
const URL = apiURLs.node.makePublic(nodeId)
return await client
.patch(URL, null, {
withCredentials: false,
Expand All @@ -256,7 +256,7 @@ export const useApi = () => {
}

const makeNotePrivate = async (nodeId: string) => {
const URL = apiURLs.makeNotePrivate(nodeId)
const URL = apiURLs.node.makePrivate(nodeId)

return await client
.patch(URL, null, {
Expand All @@ -274,7 +274,7 @@ export const useApi = () => {

const getPublicNodeAPI = async (nodeId: string) => {
const res = await client
.get(apiURLs.getPublicNode(nodeId), {
.get(apiURLs.public.getPublicNode(nodeId), {
headers: {
Accept: 'application/json, text/plain, */*'
}
Expand Down Expand Up @@ -332,7 +332,7 @@ export const useApi = () => {
}

const data = await client
.post(apiURLs.createSnippet, reqData, {
.post(apiURLs.snippet.create, reqData, {
headers: workspaceHeaders()
})
.then((d) => {
Expand All @@ -348,7 +348,7 @@ export const useApi = () => {

const getAllSnippetsByWorkspace = async () => {
const data = await client
.get(apiURLs.getAllSnippetsByWorkspace, {
.get(apiURLs.snippet.getAllSnippetsByWorkspace, {
headers: workspaceHeaders()
})
.then((d) => {
Expand Down Expand Up @@ -384,7 +384,10 @@ export const useApi = () => {
const requestData = { time: Date.now(), method: 'GET' }

res.fulfilled.forEach(async (snippet) => {
setRequest(apiURLs.getSnippetById(snippet.id), { ...requestData, url: apiURLs.getSnippetById(snippet.id) })
setRequest(apiURLs.snippet.getSnippetById(snippet.id), {
...requestData,
url: apiURLs.snippet.getSnippetById(snippet.id)
})

if (snippet) {
updateSnippet(snippet)
Expand All @@ -399,7 +402,7 @@ export const useApi = () => {
}

const getSnippetById = async (id: string) => {
const url = apiURLs.getSnippetById(id)
const url = apiURLs.snippet.getSnippetById(id)

const data = await client
.get(url, {
Expand All @@ -425,7 +428,7 @@ export const useApi = () => {
}

const data = await client
.post(apiURLs.refactorHeirarchy, reqData, {
.post(apiURLs.node.refactor, reqData, {
headers: workspaceHeaders()
})
.then((response) => {
Expand All @@ -439,6 +442,19 @@ export const useApi = () => {
return data
}

const deleteAllVersionOfSnippet = async (snippetID: string) => {
await client
.delete(apiURLs.snippet.deleteAllVersionsOfSnippet(snippetID), {
headers: workspaceHeaders()
})
.then((response) => {
mog('SnippetDeleteSuccessful')
})
.catch((error) => {
mog('SnippetDeleteFailed', { error })
})
}

return {
saveDataAPI,
getDataAPI,
Expand All @@ -452,7 +468,7 @@ export const useApi = () => {
saveSnippetAPI,
getAllSnippetsByWorkspace,
getSnippetById,
refactorHierarchy
// getNodesByWorkspace
refactorHierarchy,
deleteAllVersionOfSnippet
}
}
10 changes: 5 additions & 5 deletions apps/webapp/src/Hooks/API/useNodeShareAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useNodeShareAPI = () => {
accessType: access
}
return await client
.post(apiURLs.sharedNode, payload, {
.post(apiURLs.share.sharedNode, payload, {
headers: workspaceHeaders()
})
.then((resp) => {
Expand All @@ -47,7 +47,7 @@ export const useNodeShareAPI = () => {
userIDToAccessTypeMap
}
return await client
.put(apiURLs.sharedNode, payload, {
.put(apiURLs.share.sharedNode, payload, {
headers: workspaceHeaders()
})
.then((resp) => {
Expand All @@ -63,7 +63,7 @@ export const useNodeShareAPI = () => {
userIDs: userids
}
return await client
.delete(apiURLs.sharedNode, {
.delete(apiURLs.share.sharedNode, {
data: payload,
headers: workspaceHeaders()
})
Expand All @@ -76,7 +76,7 @@ export const useNodeShareAPI = () => {
const getAllSharedNodes = async (): Promise<SharedNodesPreset | SharedNodesErrorPreset> => {
try {
return await client
.get(apiURLs.allSharedNodes, {
.get(apiURLs.share.allSharedNodes, {
headers: workspaceHeaders()
})
.then((resp) => {
Expand Down Expand Up @@ -141,7 +141,7 @@ export const useNodeShareAPI = () => {
const getUsersOfSharedNode = async (nodeid: string): Promise<{ users: Record<string, string> }> => {
try {
return await client
.get(apiURLs.getUsersOfSharedNode(nodeid), {
.get(apiURLs.share.getUsersOfSharedNode(nodeid), {
headers: workspaceHeaders()
})
.then((resp: any) => {
Expand Down
Loading