nuxt-atproto 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -230,27 +230,40 @@ Logs out the currently authenticated user and clears the stored session data.
230
230
 
231
231
  <br />
232
232
 
233
- ### 🔢 agent
233
+ ### ➡️ isLogged()
234
234
 
235
- Provides an object containing both a public `AtpAgent` for general access and an authenticated `Agent` to perform actions that require a logged-in user, such as posting, following, and liking.
235
+ Indicates whether the user is currently authenticated.
236
236
 
237
237
  ```ts
238
238
  const atproto = useAtproto()
239
239
 
240
- const profile = await atproto.agent.public.getProfile({actor: 'owdproject.org'})
241
- console.log(profile.data)
240
+ if (atproto.isLogged()) {
241
+ console.log('User is authenticated')
242
+ } else {
243
+ console.log('User is not logged in')
244
+ }
245
+ ```
242
246
 
243
- const likedPost = await atproto.agent.account.likePost({cid, uri})
244
- console.log(likedPost.data)
247
+ **Returns**: Returns a boolean indicating whether the user is authenticated.
248
+
249
+ <br />
250
+
251
+ ## 🧩 useAgent(service?: string, fetch?: any)
252
+
253
+ A composable provided by `nuxt-atproto` that offers methods for user authentication and session management, including authenticating, signing out and session restore.
254
+
255
+ ```html
256
+
257
+ <script setup lang="ts">
258
+ const agent = useAgent('public')
259
+ </script>
245
260
  ```
246
261
 
247
262
  **Parameters:**
248
263
 
249
- - `service` (optional): The base URL of the ATProto service.
264
+ - `service` (optional): Choose between `public`, `private` or a custom service endpoint.
250
265
  - `fetch` (optional): A custom fetch implementation.
251
266
 
252
- **Returns:** An object with both public AtpAgent or authenticated account Agent.
253
-
254
267
  <br />
255
268
 
256
269
  ## License
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-atproto",
3
3
  "configKey": "atproto",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -65,7 +65,8 @@ const module = defineNuxtModule({
65
65
  JSON.stringify(_options.oauth.clientMetadata.local, null, 2)
66
66
  );
67
67
  addImportsDir(resolve("./runtime/composables"));
68
- addPlugin(resolve("./runtime/plugin.client"));
68
+ addImportsDir(resolve("./runtime/utils"));
69
+ addPlugin(resolve("./runtime/plugin"));
69
70
  }
70
71
  });
71
72
 
@@ -0,0 +1,8 @@
1
+ import { Agent } from "@atproto/api";
2
+ /**
3
+ * Provide AT Protocol agent
4
+ *
5
+ * @param service
6
+ * @param fetch
7
+ */
8
+ export declare function useAgent(service: string, fetch?: any): Agent;
@@ -0,0 +1,23 @@
1
+ import { useNuxtApp, useRuntimeConfig } from "#app";
2
+ import { Agent, AtpAgent } from "@atproto/api";
3
+ export function useAgent(service, fetch) {
4
+ const runtimeConfig = useRuntimeConfig();
5
+ const { $atproto } = useNuxtApp();
6
+ switch (service) {
7
+ case "private":
8
+ if (!$atproto.session.value) {
9
+ throw new Error("Not authenticated");
10
+ }
11
+ return new Agent($atproto.session.value);
12
+ case "public":
13
+ return new AtpAgent({
14
+ service: runtimeConfig.public.atproto.serviceEndpoint.public,
15
+ fetch
16
+ });
17
+ default:
18
+ return new AtpAgent({
19
+ service,
20
+ fetch
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,8 @@
1
+ import type { OAuthSession } from '@atproto/oauth-client';
2
+ export declare function useAtproto(service?: string, fetch?: any): {
3
+ signIn: (serviceEndpoint?: string, options?: any) => Promise<void>;
4
+ signInWithHandle: (handle?: string, options?: any) => Promise<void>;
5
+ signOut: () => Promise<void>;
6
+ restore: (did: string) => Promise<OAuthSession>;
7
+ isLogged: () => any;
8
+ };
@@ -1,6 +1,4 @@
1
- import { Agent, AtpAgent } from "@atproto/api";
2
1
  import { useRuntimeConfig, useNuxtApp } from "nuxt/app";
3
- import { reactive } from "vue";
4
2
  export function useAtproto(service, fetch) {
5
3
  const runtimeConfig = useRuntimeConfig();
6
4
  async function signIn(serviceEndpoint = runtimeConfig.public.atproto.serviceEndpoint.private, options = runtimeConfig.public.atproto.oauth.signInOptions) {
@@ -48,27 +46,15 @@ export function useAtproto(service, fetch) {
48
46
  console.log("User signed out");
49
47
  }
50
48
  }
51
- function useAgent(service2, fetch2) {
49
+ function isLogged() {
52
50
  const { $atproto } = useNuxtApp();
53
- const runtimeConfig2 = useRuntimeConfig();
54
- if (!service2) {
55
- service2 = runtimeConfig2.public.atproto.serviceEndpoint.public;
56
- }
57
- let accountAgent;
58
- if ($atproto && $atproto.session.value) {
59
- accountAgent = new Agent($atproto.session.value);
60
- }
61
- return reactive({
62
- public: new AtpAgent({ service: service2, fetch: fetch2 }),
63
- account: accountAgent
64
- });
51
+ return $atproto.session.value;
65
52
  }
66
- const agent = useAgent(service, fetch);
67
53
  return {
68
54
  signIn,
69
55
  signInWithHandle,
70
56
  signOut,
71
57
  restore,
72
- agent
58
+ isLogged
73
59
  };
74
60
  }
@@ -0,0 +1,2 @@
1
+ export declare function resolveActorDid(handle: string): Promise<string>;
2
+ export declare function resolveActorServiceEndpoint(did: string): Promise<string>;
@@ -0,0 +1,16 @@
1
+ import { useAgent } from "../composables/useAgent.js";
2
+ export async function resolveActorDid(handle) {
3
+ const agent = useAgent("public");
4
+ const { did } = await agent.com.atproto.identity.resolveHandle({
5
+ handle
6
+ }).then((result) => result.data);
7
+ return did;
8
+ }
9
+ export async function resolveActorServiceEndpoint(did) {
10
+ const response = await fetch(`https://plc.directory/${did}`);
11
+ if (!response.ok) {
12
+ throw new Error("Failed to fetch profile service endpoint");
13
+ }
14
+ const data = await response.json();
15
+ return data.service[0].serviceEndpoint;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-atproto",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Interact with AT Protocol and Bluesky in your Nuxt.js application",
5
5
  "keywords": [
6
6
  "nuxt",
File without changes