+1
-1
README.md
+1
-1
README.md
···
13
13
Refer to the [nuxt-atproto](https://www.npmjs.com/package/nuxt-atproto))) documentation for more details and options.
14
14
15
15
## Features
16
+
16
17
- Provides ATProto agent and OAuth client integration
17
18
- Generates `client-metadata.json` on the fly in `/public`
18
19
- Fetches the Open Web Desktop client account host
···
83
84
## License
84
85
85
86
This module is released under the [MIT License](LICENSE).
86
-
+44
-37
module.ts
+44
-37
module.ts
···
1
-
import {defineNuxtModule, addPlugin, createResolver, addImportsDir, installModule} from '@nuxt/kit'
2
-
import {getAtprotoDesktopOwner} from "./runtime/utils/utilAtprotoDesktop";
3
-
import {AtpAgent} from "@atproto/api";
1
+
import {
2
+
defineNuxtModule,
3
+
addPlugin,
4
+
createResolver,
5
+
addImportsDir,
6
+
installModule,
7
+
} from '@nuxt/kit'
8
+
import { getAtprotoDesktopOwner } from './runtime/utils/utilAtprotoDesktop'
9
+
import { AtpAgent } from '@atproto/api'
4
10
5
-
const {resolve} = createResolver(import.meta.url)
11
+
const { resolve } = createResolver(import.meta.url)
6
12
7
13
export default defineNuxtModule({
8
-
meta: {
9
-
name: 'owd-module-atproto',
10
-
configKey: 'atprotoDesktop',
14
+
meta: {
15
+
name: 'owd-module-atproto',
16
+
configKey: 'atprotoDesktop',
17
+
},
18
+
defaults: {
19
+
owner: {
20
+
did: 'did:plc:iaf5ejdchj6nydfxmcrq5rm6',
11
21
},
12
-
defaults: {
13
-
owner: {
14
-
did: 'did:plc:iaf5ejdchj6nydfxmcrq5rm6',
15
-
},
16
-
name: {
17
-
title: 'atproto',
18
-
affix: 'OS'
19
-
},
22
+
name: {
23
+
title: 'atproto',
24
+
affix: 'OS',
20
25
},
21
-
async setup(options: AtprotoDesktopOptions, _nuxt) {
22
-
await installModule('nuxt-atproto')
26
+
},
27
+
async setup(options: AtprotoDesktopOptions, _nuxt) {
28
+
await installModule('nuxt-atproto')
23
29
24
-
// configure aliases
25
-
26
-
_nuxt.options.alias ||= {}
27
-
28
-
_nuxt.options.alias['@owdproject/module-atproto'] = resolve(__dirname, '.')
30
+
// configure aliases
29
31
30
-
// set runtime config
31
-
_nuxt.options.runtimeConfig.public.atprotoDesktop = options
32
+
_nuxt.options.alias ||= {}
32
33
33
-
// retrieve owd owner profile from atproto
34
+
_nuxt.options.alias['@owdproject/module-atproto'] = resolve(__dirname, '.')
34
35
35
-
_nuxt.options.runtimeConfig.public.atprotoDesktop.owner.profile = await getAtprotoDesktopOwner(
36
-
new AtpAgent({
37
-
service: _nuxt.options.atproto.serviceEndpoint.public,
38
-
}),
39
-
_nuxt.options.runtimeConfig.public.atprotoDesktop.owner.did
40
-
)
36
+
// retrieve owd owner profile from atproto
41
37
42
-
{
38
+
options.owner.profile = await getAtprotoDesktopOwner(
39
+
new AtpAgent({
40
+
service: _nuxt.options.atproto.serviceEndpoint.public,
41
+
}),
42
+
options.owner.did,
43
+
)
43
44
44
-
// import data
45
-
addImportsDir(resolve('./runtime/composables'))
46
-
addImportsDir(resolve('./runtime/stores'))
47
-
addPlugin(resolve('./runtime/plugin'))
45
+
// set runtime config
46
+
_nuxt.options.runtimeConfig.public.atprotoDesktop = options
48
47
49
-
}
48
+
{
49
+
// import data
50
+
addImportsDir(resolve('./runtime/composables'))
51
+
addImportsDir(resolve('./runtime/stores'))
52
+
addPlugin({
53
+
src: resolve('./runtime/plugin'),
54
+
mode: 'client',
55
+
})
50
56
}
57
+
},
51
58
})
+1
-1
package.json
+1
-1
package.json
+21
-21
runtime/plugin.ts
+21
-21
runtime/plugin.ts
···
1
-
import {useAtprotoAccountStore} from "./stores/storeAtprotoAccount";
2
-
import {defineNuxtPlugin} from "nuxt/app"
1
+
import { useAtprotoAccountStore } from './stores/storeAtprotoAccount'
2
+
import { defineNuxtPlugin } from 'nuxt/app'
3
3
import { useAtproto } from '#imports'
4
4
5
5
export default defineNuxtPlugin({
6
-
name: 'owd-plugin-atproto',
7
-
parallel: true,
8
-
async setup(nuxtApp) {
9
-
const atprotoAccountStore = useAtprotoAccountStore()
10
-
// handle oauth callback + session restore
6
+
name: 'owd-plugin-atproto',
7
+
parallel: true,
8
+
async setup(nuxtApp) {
9
+
const atprotoAccountStore = useAtprotoAccountStore()
10
+
// handle oauth callback + session restore
11
11
12
-
nuxtApp.hook('app:mounted', async () => {
13
-
const atproto = useAtproto()
12
+
nuxtApp.hook('app:mounted', async () => {
13
+
const atproto = useAtproto()
14
14
15
-
if (atproto.agent.account) {
16
-
atprotoAccountStore.setAccountState('fetching', true)
15
+
if (atproto.agent.account) {
16
+
atprotoAccountStore.setAccountState('fetching', true)
17
17
18
-
await atproto.agent.public
19
-
.getProfile({
20
-
actor: atproto.agent.account.assertDid
21
-
})
22
-
.then((profile) => {
23
-
atprotoAccountStore.setAccount(profile.data)
24
-
})
25
-
}
26
-
})
27
-
}
18
+
await atproto.agent.public
19
+
.getProfile({
20
+
actor: atproto.agent.account.assertDid,
21
+
})
22
+
.then((profile) => {
23
+
atprotoAccountStore.setAccount(profile.data)
24
+
})
25
+
}
26
+
})
27
+
},
28
28
})
+37
-34
runtime/stores/storeAtprotoAccount.ts
+37
-34
runtime/stores/storeAtprotoAccount.ts
···
1
-
import {defineStore} from "pinia"
2
-
import {ref, reactive, computed} from "@vue/reactivity"
3
-
import {useRuntimeConfig} from "nuxt/app"
1
+
import { defineStore } from 'pinia'
2
+
import { ref, reactive, computed } from '@vue/reactivity'
3
+
import { useRuntimeConfig } from 'nuxt/app'
4
4
5
-
export const useAtprotoAccountStore = defineStore('owd/atproto/account', () => {
5
+
export const useAtprotoAccountStore = defineStore(
6
+
'owd/atproto/account',
7
+
() => {
6
8
const runtimeConfig = useRuntimeConfig()
7
9
8
-
const session = ref<any|undefined>()
9
-
const account = ref<any|undefined>()
10
-
const handleResolver = ref<string>(runtimeConfig.public.atproto.serviceEndpoint.private)
10
+
const session = ref<any | undefined>()
11
+
const account = ref<any | undefined>()
12
+
const handleResolver = ref<string>(
13
+
runtimeConfig.public.atproto.serviceEndpoint.private,
14
+
)
11
15
12
16
const state = reactive<{
13
-
fetching: boolean
17
+
fetching: boolean
14
18
}>({
15
-
fetching: false,
19
+
fetching: false,
16
20
})
17
21
18
22
const isAccountLogged = computed(() => {
19
-
return !!account.value
23
+
return !!account.value
20
24
})
21
25
22
26
const handleResolverHostname = computed(() => {
23
-
return new URL(handleResolver.value).hostname
27
+
return new URL(handleResolver.value).hostname
24
28
})
25
29
26
30
function setAccount(value: any | undefined) {
27
-
account.value = value
28
-
state.fetching = false
31
+
account.value = value
32
+
state.fetching = false
29
33
}
30
34
31
-
function setAccountState(
32
-
key: 'fetching',
33
-
value: boolean
34
-
) {
35
-
state[key] = value
35
+
function setAccountState(key: 'fetching', value: boolean) {
36
+
state[key] = value
36
37
}
37
38
38
39
function reset() {
39
-
session.value = undefined
40
-
account.value = undefined
40
+
session.value = undefined
41
+
account.value = undefined
41
42
}
42
43
43
44
return {
44
-
session,
45
-
account,
46
-
handleResolver,
47
-
handleResolverHostname,
48
-
state,
49
-
isAccountLogged,
50
-
setAccount,
51
-
setAccountState,
52
-
reset,
45
+
session,
46
+
account,
47
+
handleResolver,
48
+
handleResolverHostname,
49
+
state,
50
+
isAccountLogged,
51
+
setAccount,
52
+
setAccountState,
53
+
reset,
53
54
}
54
-
}, {
55
+
},
56
+
{
55
57
persistedState: {
56
-
persist: true,
57
-
includePaths: ['handleResolver']
58
-
}
59
-
})
58
+
persist: true,
59
+
includePaths: ['handleResolver'],
60
+
},
61
+
},
62
+
)
+5
-5
runtime/utils/utilAtprotoDesktop.ts
+5
-5
runtime/utils/utilAtprotoDesktop.ts
···
1
-
import {AppBskyActorDefs} from "@atproto/api";
1
+
import { AppBskyActorDefs } from '@atproto/api'
2
2
3
3
export async function getAtprotoDesktopOwner(agent: any, did: string) {
4
-
return agent
5
-
.getProfile({ actor: did })
6
-
.then((result: {data:AppBskyActorDefs.ProfileView}) => result.data)
7
-
}
4
+
return agent
5
+
.getProfile({ actor: did })
6
+
.then((result: { data: AppBskyActorDefs.ProfileView }) => result.data)
7
+
}
+4
-4
runtime/utils/utilRoute.ts
+4
-4
runtime/utils/utilRoute.ts
···
1
1
export function routeAtprotoOS(path?: string) {
2
-
return `https://github.com/atproto-os` + path
2
+
return 'https://github.com/atproto-os' + path
3
3
}
4
4
5
5
export function routeBluesky(path?: string) {
6
-
return `https://bsky.app` + path
6
+
return 'https://bsky.app' + path
7
7
}
8
8
9
9
export function routeBlueskyProfile(handle: string) {
10
-
return routeBluesky(`/profile/${handle}`)
11
-
}
10
+
return routeBluesky(`/profile/${handle}`)
11
+
}
+10
-10
types/index.d.ts
+10
-10
types/index.d.ts
···
1
1
interface AtprotoDesktopOptions {
2
-
owner: {
3
-
domain?: string
4
-
did: string
5
-
profile?: any
6
-
},
7
-
name: {
8
-
title: string
9
-
affix: string
10
-
}
11
-
}
2
+
owner: {
3
+
domain?: string
4
+
did: string
5
+
profile?: any
6
+
}
7
+
name: {
8
+
title: string
9
+
affix: string
10
+
}
11
+
}