Files
speckle-server/packages/frontend-2/lib/integrations/composables/useAccIntegration.ts
T
Oğuzhan Koral 05e00d2c5c feat(acc): revamp (#5501)
* chore(acc): put permission gql in correct place

* feat(acc): swap to new rvt import

* fix(acc): add oda secrets

* feat(acc): auth cookies

* feat(acc): introduce integrations as workspace setting

* feat(acc): create sync item from models

* fix(acc): bump

* fix(acc): naming lost in merge

* feat(acc): no acc tab - table under settings

* chore(acc): new sync but will disapper

* feat(acc): see statuses over model list

* chore(acc): fix return type

* chore(acc): type saga

* chore(acc): status badge

* chore(acc): refactor acc gql (#5556)

* checkpoint

* fix(acc): refactor gql items

* feat(acc): double button

* chore(acc): gqlgen

* fix(acc): model ids are not project ids

* chore(acc): bump function version

* chore(acc): split up clients

* feat(acc): more-optimised gql folder fetching schema

* feat(acc): acc folder contents gql impl

* feat(acc): apollo cache optimisations

* chore(acc): gqlgen

* fix(acc): return something for

* fix(acc): handle null values correctly

* chore(acc): specify prod functions

---------

Co-authored-by: Chuck Driesler <chuck@speckle.systems>
2025-10-03 13:54:17 +01:00

70 lines
2.2 KiB
TypeScript

import { useApolloClient } from '@vue/apollo-composable'
import { useAccAuthManager } from '~/lib/acc/composables/useAccAuthManager'
import { AccIntegration } from '~/lib/acc/types'
import { WorkspaceFeatureName } from '~/lib/common/generated/gql/graphql'
import type { Integration } from '~/lib/integrations/types'
import { workspaceFeatureEnabledCheckQuery } from '~/lib/workspaces/graphql/queries'
export function useAccIntegration() {
const integration = ref<Integration>(AccIntegration)
const apollo = useApolloClient().client
const loading = ref(false)
const checkConnection = async (workspaceSlug: string, workspaceId: string) => {
loading.value = true
try {
const isAccModuleEnabled = useIsAccModuleEnabled()
if (isAccModuleEnabled) {
const accIntegationEnabled = await isAccEnabledInWorkspace(workspaceId)
const callbackEndpoint = `settings/workspaces/${workspaceSlug}/integrations`
if (accIntegationEnabled) {
const { isExpired, tokens, tryGetTokensFromCookies } = useAccAuthManager()
await tryGetTokensFromCookies() // also refreshes the tokens - so we can rely on existance of tokens to say 'connected'
integration.value = {
...AccIntegration,
connected: tokens.value !== undefined,
status: isExpired.value
? 'expired'
: tokens.value !== undefined
? 'connected'
: 'notConnected',
enabled: true,
callbackEndpoint
}
} else {
integration.value = { ...AccIntegration, callbackEndpoint }
}
}
} finally {
loading.value = false
}
}
const isAccEnabledInWorkspace = async (workspaceId: string) => {
const { data } = await apollo.query({
query: workspaceFeatureEnabledCheckQuery,
variables: {
workspaceId,
featureName: WorkspaceFeatureName.AccIntegration
},
fetchPolicy: 'network-only'
})
return data?.workspace?.hasAccessToFeature ?? false
}
const checkCredientials = async () => {
const { tryGetTokensFromCookies } = useAccAuthManager()
await tryGetTokensFromCookies()
}
return {
loading,
integration,
checkConnection,
checkCredientials
}
}